{"name":"unistore","version":"2.2.0","description":"Dead simple centralized state container (store) with preact bindings.","source":"unistore.js","module":"dist/unistore.es.js","main":"dist/unistore.js","umd:main":"dist/unistore.umd.js","scripts":{"build":"npm run -s transpile && npm run -s size && npm run -s docs","transpile":"rollup -c --environment FORMAT:umd && rollup -c --environment FORMAT:cjs && rollup -c --environment FORMAT:es","size":"strip-json-comments --no-whitespace dist/unistore.js | gzip-size","docs":"documentation readme unistore.js -q --section API","test":"eslint unistore.js && jest","prepublishOnly":"npm run build"},"eslintConfig":{"extends":"eslint-config-synacor","globals":{"jest":1},"rules":{"eqeqeq":0,"guard-for-in":0,"prefer-rest-params":0}},"babel":{"presets":["es2015"],"plugins":[["transform-react-jsx",{"pragma":"h"}]]},"files":["unistore.js","dist"],"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-es2015":"^6.24.1","documentation":"^4.0.0","eslint":"^4.12.1","eslint-config-synacor":"^2.0.2","gzip-size":"^3.0.0","jest":"^21.2.1","preact":"^8.2.6","rollup":"^0.52.1","rollup-plugin-buble":"^0.18.0","rollup-plugin-es3":"^1.0.3","rollup-plugin-post-replace":"^1.0.0","rollup-plugin-uglify":"^2.0.1","strip-json-comments-cli":"^1.0.1","uglify-js":"^2.8.29"},"peerDependencies":{"preact":"*"},"dependencies":{},"gitHead":"23b678e9a340a6f0d5fc62f69d09848ef0daf5e1","bugs":{"url":"https://github.com/developit/unistore/issues"},"homepage":"https://github.com/developit/unistore#readme","_id":"unistore@2.2.0","_npmVersion":"5.5.1","_nodeVersion":"8.7.0","_npmUser":{"name":"developit","email":"jason@developit.ca"},"dist":{"integrity":"sha512-wUKqX/cmIYWPtPNT+gIUO9f87E7XlWDLEhj1ureaFc2ePTa+Q33Kg1AQBXT+XSbgeN20w6euAZJXf45hhfHAXQ==","shasum":"7f808977f2b6a0723e10954337975d4915ccfad7","tarball":"http://registry-npm.ywwl.com/unistore/download/unistore-2.2.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBAZ3PnG7SaJGY9jYiM/M1B0STQaJ9JRtBA5HWgZSMrnAiEAjYq5To9nNARgNIPa7jZMVfcuHoYMTTRqRsy21KdiFwU="}],"size":5930,"noattachment":false,"key":"/unistore/-/unistore-2.2.0.tgz"},"maintainers":[{"email":"jason@developit.ca","name":"developit"},{"email":"garth22@gmail.com","name":"gdub"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/unistore-2.2.0.tgz_1512595897590_0.030270862160250545"},"directories":{},"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":1512595898569,"_cnpm_publish_time":1512595898569,"dist-tags":{"latest":"3.5.2"}}