{"name":"unistore","version":"3.3.2","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":"750b"},{"path":"dist/unistore.js","maxSize":"400b"},{"path":"preact.js","maxSize":"600b"}],"babel":{"presets":[["env",{"targets":{"node":true}}]],"plugins":[["transform-react-jsx",{"pragma":"h"}]]},"jest":{"testURL":"http://localhost"},"keywords":["preact","component","state machine","redux"],"repository":{"type":"git","url":"git+https://github.com/developit/unistore.git"},"author":{"name":"Jason Miller","email":"jason@developit.ca"},"license":"MIT","devDependencies":{"babel-jest":"^21.2.0","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":"^23.6.0","microbundle":"^0.11.0","npm-run-all":"^4.1.2","preact":"^8.4.2","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":"2af6cd366ec02d6d1cdb25892a4ec8c14bb3ef6f","bugs":{"url":"https://github.com/developit/unistore/issues"},"homepage":"https://github.com/developit/unistore#readme","_id":"unistore@3.3.2","_npmVersion":"6.4.1","_nodeVersion":"10.15.0","_npmUser":{"name":"developit","email":"jason@developit.ca"},"dist":{"integrity":"sha512-TPs1P3HLe7/L6oSmSHcIshfgbuVLA5ex+VFD4X6DwGyiWhGOD/O7mbldwraEpaq/fU0jGg9fQ89WlZtqxWf4uQ==","shasum":"6c96302191d18fc3d474f19db9fb52a5f878b552","tarball":"http://registry-npm.ywwl.com/unistore/download/unistore-3.3.2.tgz","fileCount":35,"unpackedSize":119389,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcgaM6CRA9TVsSAnZWagAAC/MP/1qTibCgx2ym/AhRvvx/\n6qr41GY5xCnDDkL4TwP8q176sZskiCPw+HkoARZi7v3hR3NdL2d/4/3UHt18\nXXRaHEJm2CmPIjd10I2FChQByD0mckQkcav0pEwW3mbUD873TJqjeVqXjPfw\nTJMXPII0REikS91Bp7ukqT9QwhJapV97eur42rohdisPEAlLCLiZoB/BmSEE\n9oAUantXpMBGaGeNHe+srPnpOnY0LLs2z6YU1HEYDhR3964MNvJ4ep+VUbNO\nIZrgBeVqCkFO2+StpRWJQdfe7vDKqtmrdr9IerCSBClrWe+owl24oaLd2jY2\nvHfGqrxZZR/HEqlh/dDayhsDf5fEfbd4rC2I3s8Lj/C1LsG/SyqBplbfinDY\nB93N63MLmhtvrU405WdxDReIc7JZ3HETJ18izdLvgHvnVN6sIsEfMBgpYLR8\n72WaZub8XDMXz/z5fWPLErxqHStm+vlAi3fXEtwDTovARRNL50Olcq1sZVUz\nKmlteXYeivIRtKSt5hq1/Joi7RA+HsW0JY3itXsS3pBUR2URryMLu6TJgl0C\nHsctH7urvindBsV/tVrTIrzpGvP+Nfgddc0BKYisRjWvrPJpQp7I4yTrAZ32\n6Zm2VEoYuTi2BD2I6gfNWWy+vTMQ7nFtGN4etb3ShEI72+XdYb6DO50NsDdr\nZUOu\r\n=Y4bR\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD45KN7ckFvi+rHmTH2cUegIhGQKuxUxCwPgohw825fCwIgQy/LyDd7Y4ncgWuhiC5MLtzzQsq8WGDIPm0V542DZvg="}],"size":17555,"noattachment":false,"key":"/unistore/-/unistore-3.3.2.tgz"},"maintainers":[{"name":"developit","email":"jason@developit.ca"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/unistore_3.3.2_1551999802313_0.6847909011319004"},"_hasShrinkwrap":false,"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, stuff: [] })\n\nlet actions = {\n  // Actions can just return a state update:\n  increment(state) {\n    // The returned object will be merged into the current 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  // See the \"Increment by 10\"-button below\n  incrementBy: ({ count }, incrementAmount) => {\n    return { count: count+incrementAmount }\n  },\n}\n\n// If actions is a function, it gets passed the store:\nlet actionFunctions = store => ({\n  // Async actions can be pure async/promise functions:\n  async getStuff(state) {\n    const res = await fetch('/foo.json')\n    return { stuff: await res.json() }\n  },\n\n  // ... or just actions that call store.setState() later:\n  clearOutStuff(state) {\n    setTimeout(() => {\n      store.setState({ stuff: [] }) // clear 'stuff' after 1 second\n    }, 1000)\n  }\n\n  // Remember that the state passed to the action function could be stale after\n  // doing async work, so use getState() instead:\n  async incrementAfterStuff(state) {\n    const res = await fetch('foo.json')\n    const resJson = await res.json()\n    // the variable 'state' above could now be old,\n    // better get a new one from the store\n    const upToDateState = store.getState()\n\n    return {\n      stuff: resJson,\n      count: upToDateState.count + resJson.length,\n    }\n  }\n})\n\n// Connecting a react/preact component to get current state and to bind actions\nconst App1 = connect('count', actions)(\n  ({ count, increment, incrementBy }) => (\n    <div>\n      <p>Count: {count}</p>\n      <button onClick={increment}>Increment</button>\n      <button onClick={() => incrementBy(10)}>Increment by 10</button>\n    </div>\n  )\n)\n\n// First argument to connect can also be a string, array or function while\n// second argument can be an object or a function. Here we pass an array and\n// a function.\nconst App2 = connect(['count', 'stuff'], actionFunctions)(\n  ({ count, stuff, getStuff, clearOutStuff, incrementAfterStuff }) => (\n    <div>\n      <p>Count: {count}</p>\n      <p>Stuff:\n        <ul>{stuff.map(s => (\n         <li>{s.name}</li>\n        ))}</ul>\n      </p>\n      <button onClick={getStuff}>Get some stuff!</button>\n      <button onClick={clearOutStuff}>Remove all stuff!</button>\n      <button onClick={incrementAfterStuff}>Get and count stuff!</button>\n    </div>\n  )\n)\n\nexport const getApp1 = () => (\n  <Provider store={store}>\n    <App1 />\n  </Provider>\n)\n\nexport const getApp2 = () => (\n  <Provider store={store}>\n    <App2 />\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","publish_time":1551999802462,"_cnpm_publish_time":1551999802462,"dist-tags":{"latest":"3.5.2"}}