{"_id":"@eduardoborges/unistore","_rev":"1-56dba148f706917d1e053b0c15e629d4","name":"@eduardoborges/unistore","dist-tags":{"latest":"3.4.1"},"versions":{"3.4.1":{"name":"@eduardoborges/unistore","version":"3.4.1","description":"Dead simple centralized state container (store) with preact and react bindings.","source":"src/index.js","module":"dist/unistore.es.js","main":"dist/unistore.js","umd:main":"dist/unistore.umd.js","typings":"index.d.ts","scripts":{"build":"npm-run-all --silent -p build:main build:integrations build:combined -s size docs","build:main":"microbundle","build:integrations":"microbundle src/integrations/*.js -o x.js -f cjs --external react,preact","build:combined":"microbundle src/combined/*.js -o full/x.js --external react,preact","size":"strip-json-comments --no-whitespace dist/unistore.js | gzip-size && bundlesize","docs":"documentation readme src/index.js src/integrations/preact.js -q --section API && npm run -s fixreadme","fixreadme":"node -e 'var fs=require(\"fs\");fs.writeFileSync(\"README.md\", fs.readFileSync(\"README.md\", \"utf8\").replace(/^-   /gm, \"- \"))'","test":"eslint src && npm run build && jest","prepare":"npm t","release":"npm t && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"},"eslintConfig":{"extends":"eslint-config-developit","rules":{"prefer-rest-params":0}},"bundlesize":[{"path":"full/preact.js","maxSize":"760b"},{"path":"dist/unistore.js","maxSize":"400b"},{"path":"preact.js","maxSize":"600b"}],"babel":{"presets":[["env",{"targets":{"node":"current"}}]],"plugins":[["transform-react-jsx",{"pragma":"h"}]]},"jest":{"testURL":"http://localhost"},"keywords":["preact","component","state machine","redux"],"repository":{"type":"git","url":"git+https://github.com/eduardoborges/unistore.git"},"author":{"name":"Jason Miller","email":"jason@developit.ca"},"license":"MIT","devDependencies":{"babel-jest":"^24.3.1","babel-plugin-transform-react-jsx":"^6.24.1","babel-preset-env":"^1.6.1","bundlesize":"^0.17.1","documentation":"^4.0.0","enzyme":"^3.9.0","enzyme-adapter-react-16":"^1.10.0","eslint":"^4.16.0","eslint-config-developit":"^1.1.1","gzip-size-cli":"^2.1.0","jest":"^24.3.1","microbundle":"^0.11.0","npm-run-all":"^4.1.2","preact":"^10.0.0-alpha.1","raf":"^3.4.0","react":"^16.8.4","react-dom":"^16.8.4","strip-json-comments-cli":"^1.0.1"},"peerDependenciesMeta":{"preact":{"optional":true},"react":{"optional":true}},"gitHead":"fd29c99178f8ff31cc31dd28eecd000c226d9309","bugs":{"url":"https://github.com/eduardoborges/unistore/issues"},"homepage":"https://github.com/eduardoborges/unistore#readme","_id":"@eduardoborges/unistore@3.4.1","_nodeVersion":"10.15.1","_npmVersion":"6.9.0","dist":{"integrity":"sha512-lYi24cpMSlyWvJKCURnPA2pIXbxs+tQblxobZeWt3Ol8LCpXgqq3+FW5efPRqD1jVeNuh+UlO1LD0P34EIijxQ==","shasum":"1c972a8d27b29130ffff633ff70a979f5c7d3ff6","tarball":"https://registry.npmjs.org/@eduardoborges/unistore/-/unistore-3.4.1.tgz","fileCount":35,"unpackedSize":120962,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdYvz5CRA9TVsSAnZWagAA2vEP/iK8WswIv4HMv9RB1/01\nC9fqqyCsuww6EG9hJ2wZ3+tZJNXpqwJFnAXMJ1GvDiOQKsduzlXXudm2Dv3G\nvP2iKHlOUIeGvPUwK0TdC3CK2RN9lqHiXy/fX+8Mb7IIbQCB40sblJuOJBoP\nvgfUeGyb2Av5ACUM/OA0NpbzbVZI1Pzov2wVPs5RhguoPT+bNBQA5A/USHmc\nf6vGeO0GP/HuofLszTWghAKWaETwd4WQyHyk2V6bjhONFQAyqGj3umoWfbab\n8ShIlLmwDr3E/rJpozIzdMVGscoB+1SsbzkS2hFCOh09vvHShUjU/Mi2D0xu\nz+/uf0ezuthUyr70oyK3HlMLLv6Z0PrtcQlTWUNKfmwdBq3BTUG2mzZkkZca\nLLVUBqfFC+A2c7h9RdRPlZsQASyWMZHHGTlPmcaB3UQuEA7NTp+dB7AhUq6C\n0EZHSGCN8XzUCs7Vz/EgvWlemdPe8I4fH/YybUAUHD+9J0A+GrOrbgDHxLIS\njjz1Bv5SSnnNIzUpcfDq3mJ8oxNedDTWh/pv0+FWVIvTnbhccM2bzvwRdpbl\nAdYRcUqpM8ser90NuCOzMC3ejQEwN5IhAxl7Xo5lBMQcxP62z6FF61nX3Qbq\niHyMFxvJX1Kb92WqCXdcReMh6+eWDYBWSJGxQ1f+PJ3IK/I57F+atmaTlIvx\nNXQx\r\n=KtgM\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDQobQuDWHXT52knSNweixiFLoKG05K4uIiFxeAYCbqKwIhANK0AKTmYISlTEl+6aYY4KuRWN0hgQ1a5pWOPfrYGUai"}]},"maintainers":[{"name":"eduardoborges","email":"euduardoborges@gmail.com"}],"_npmUser":{"name":"eduardoborges","email":"euduardoborges@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/unistore_3.4.1_1566768377118_0.8482085347429944"},"_hasShrinkwrap":false}},"time":{"created":"2019-08-25T21:26:16.911Z","3.4.1":"2019-08-25T21:26:17.265Z","modified":"2022-04-05T06:43:48.546Z"},"maintainers":[{"name":"eduardoborges","email":"euduardoborges@gmail.com"}],"description":"Dead simple centralized state container (store) with preact and react bindings.","homepage":"https://github.com/eduardoborges/unistore#readme","keywords":["preact","component","state machine","redux"],"repository":{"type":"git","url":"git+https://github.com/eduardoborges/unistore.git"},"author":{"name":"Jason Miller","email":"jason@developit.ca"},"bugs":{"url":"https://github.com/eduardoborges/unistore/issues"},"license":"MIT","readme":"<p align=\"center\">\n  <img src=\"https://i.imgur.com/o0u6dto.png\" width=\"300\" height=\"300\" alt=\"unistore\">\n  <br>\n  <a href=\"https://www.npmjs.org/package/unistore\"><img src=\"https://img.shields.io/npm/v/unistore.svg?style=flat\" alt=\"npm\"></a> <a href=\"https://travis-ci.org/developit/unistore\"><img src=\"https://travis-ci.org/developit/unistore.svg?branch=master\" alt=\"travis\"></a>\n</p>\n\n# unistore\n\n> A tiny 350b centralized state container with component bindings for [Preact] & [React].\n\n- **Small** footprint complements Preact nicely _(unistore + unistore/preact is ~650b)_\n- **Familiar** names and ideas from Redux-like libraries\n- **Useful** data selectors to extract properties from state\n- **Portable** actions can be moved into a common place and imported\n- **Functional** actions are just reducers\n- **NEW**: seamlessly run Unistore in a worker via [Stockroom](https://github.com/developit/stockroom)\n\n## Table of Contents\n\n- [Install](#install)\n- [Usage](#usage)\n- [Examples](#examples)\n- [API](#api)\n- [License](#license)\n\n## Install\n\nThis project uses [node](http://nodejs.org) and [npm](https://npmjs.com). Go check them out if you don't have them locally installed.\n\n```sh\nnpm install --save unistore\n```\n\nThen with a module bundler like [webpack](https://webpack.js.org) or [rollup](http://rollupjs.org), use as you would anything else:\n\n```js\n// The store:\nimport createStore from 'unistore'\n\n// Preact integration\nimport { Provider, connect } from 'unistore/preact'\n\n// React integration\nimport { Provider, connect } from 'unistore/react'\n```\n\nAlternatively, you can import the \"full\" build for each, which includes both `createStore` and the integration for your library of choice:\n\n```js\nimport { createStore, Provider, connect } from 'unistore/full/preact'\n```\n\nThe [UMD](https://github.com/umdjs/umd) build is also available on [unpkg](https://unpkg.com):\n\n```html\n<!-- just unistore(): -->\n<script src=\"https://unpkg.com/unistore/dist/unistore.umd.js\"></script>\n<!-- for preact -->\n<script src=\"https://unpkg.com/unistore/full/preact.umd.js\"></script>\n<!-- for react -->\n<script src=\"https://unpkg.com/unistore/full/react.umd.js\"></script>\n```\n\nYou can find the library on `window.unistore`.\n\n### Usage\n\n```js\nimport createStore from 'unistore'\nimport { Provider, connect } from 'unistore/preact'\n\nlet store = createStore({ count: 0 })\n\n// If actions is a function, it gets passed the store:\nlet actions = store => ({\n  // Actions can just return a state update:\n  increment(state) {\n    return { count: state.count+1 }\n  },\n\n  // The above example as an Arrow Function:\n  increment2: ({ count }) => ({ count: count+1 }),\n\n  //Actions receive current state as first parameter and any other params next\n  //check this function as <button onClick={incrementAndLog}>\n  incrementAndLog: ({ count }, event) => {\n    console.info(event)\n    return { count: count+1 }\n  },\n\n  // Async actions can be pure async/promise functions:\n  async getStuff(state) {\n    let res = await fetch('/foo.json')\n    return { stuff: await res.json() }\n  },\n\n  // ... or just actions that call store.setState() later:\n  incrementAsync(state) {\n    setTimeout( () => {\n      store.setState({ count: state.count+1 })\n    }, 100)\n  }\n})\n\nconst App = connect('count', actions)(\n  ({ count, increment }) => (\n    <div>\n      <p>Count: {count}</p>\n      <button onClick={increment}>Increment</button>\n    </div>\n  )\n)\n\nexport default () => (\n  <Provider store={store}>\n    <App />\n  </Provider>\n)\n```\n\n### Debug\n\nMake sure to have [Redux devtools extension](https://github.com/zalmoxisus/redux-devtools-extension) previously installed.\n\n```js\nimport createStore from 'unistore'\nimport devtools    from 'unistore/devtools'\n\nlet initialState = { count: 0 };\nlet store = process.env.NODE_ENV === 'production' ?  createStore(initialState) : devtools(createStore(initialState));\n\n// ...\n```\n\n### Examples\n\n[README Example on CodeSandbox](https://codesandbox.io/s/l7y7w5qkz9)\n\n### API\n\n<!-- Generated by documentation.js. Update this documentation by updating the source code. -->\n\n#### createStore\n\nCreates a new store, which is a tiny evented state container.\n\n**Parameters**\n\n- `state` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional initial state (optional, default `{}`)\n\n**Examples**\n\n```javascript\nlet store = createStore();\nstore.subscribe( state => console.log(state) );\nstore.setState({ a: 'b' });   // logs { a: 'b' }\nstore.setState({ c: 'd' });   // logs { a: 'b', c: 'd' }\n```\n\nReturns **[store](#store)** \n\n#### store\n\nAn observable state container, returned from [createStore](#createstore)\n\n##### action\n\nCreate a bound copy of the given action function.\nThe bound returned function invokes action() and persists the result back to the store.\nIf the return value of `action` is a Promise, the resolved value will be used as state.\n\n**Parameters**\n\n- `action` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** An action of the form `action(state, ...args) -> stateUpdate`\n\nReturns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** boundAction()\n\n##### setState\n\nApply a partial state object to the current state, invoking registered listeners.\n\n**Parameters**\n\n- `update` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** An object with properties to be merged into state\n- `overwrite` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** If `true`, update will replace state instead of being merged into it (optional, default `false`)\n\n##### subscribe\n\nRegister a listener function to be called whenever state is changed. Returns an `unsubscribe()` function.\n\n**Parameters**\n\n- `listener` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** A function to call when state changes. Gets passed the new state.\n\nReturns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** unsubscribe()\n\n##### unsubscribe\n\nRemove a previously-registered listener function.\n\n**Parameters**\n\n- `listener` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** The callback previously passed to `subscribe()` that should be removed.\n\n##### getState\n\nRetrieve the current state object.\n\nReturns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** state\n\n#### connect\n\nWire a component up to the store. Passes state as props, re-renders on change.\n\n**Parameters**\n\n- `mapStateToProps` **([Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function) \\| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) \\| [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))** A function mapping of store state to prop values, or an array/CSV of properties to map.\n- `actions` **([Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function) \\| [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))?** Action functions (pure state mappings), or a factory returning them. Every action function gets current state as the first parameter and any other params next\n\n**Examples**\n\n```javascript\nconst Foo = connect('foo,bar')( ({ foo, bar }) => <div /> )\n```\n\n```javascript\nconst actions = { someAction }\nconst Foo = connect('foo,bar', actions)( ({ foo, bar, someAction }) => <div /> )\n```\n\nReturns **Component** ConnectedComponent\n\n#### Provider\n\n**Extends Component**\n\nProvider exposes a store (passed as `props.store`) into context.\n\nGenerally, an entire application is wrapped in a single `<Provider>` at the root.\n\n**Parameters**\n\n- `props` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** \n    -   `props.store` **Store** A {Store} instance to expose via context.\n\n### Reporting Issues\n\nFound a problem? Want a new feature? First of all, see if your issue or idea has [already been reported](../../issues).\nIf not, just open a [new clear and descriptive issue](../../issues/new).\n\n### License\n\n[MIT License](https://oss.ninja/mit/developit) © [Jason Miller](https://jasonformat.com)\n\n[preact]: https://github.com/developit/preact\n\n[react]: https://github.com/facebook/react\n","readmeFilename":"README.md"}