{"_id":"stockroom","_rev":"2-e2d18d78f0c90605adee27be05db18eb","name":"stockroom","description":"Offload your store management to a worker.","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"stockroom","version":"1.0.0","description":"Offload your store management to a worker.","source":"src/index.js","module":"dist/stockroom.es.js","main":"dist/stockroom.js","umd:main":"dist/stockroom.umd.js","typings":"index.d.ts","scripts":{"build":"npm-run-all --silent bundle size docs","bundle":"microbundle src/index.js -o dist/stockroom.js && microbundle src/inline.js -o inline/index.js && microbundle src/worker.js -o worker/index.js","size":"strip-json-comments --no-whitespace dist/stockroom.js | gzip-size && bundlesize","docs":"documentation readme src/*.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 test && npm run bundle && karma start test/karma.conf.js --single-run","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,"jest/valid-expect":0}},"bundlesize":[{"path":"dist/stockroom.js","maxSize":"1kb"},{"path":"worker/index.js","maxSize":"1kb"},{"path":"inline/index.js","maxSize":"300b"}],"files":["src","dist","inline","worker"],"keywords":["preact","unistore","state machine","worker","threads","redux"],"repository":{"type":"git","url":"git+https://github.com/developit/stockroom.git"},"author":{"name":"Jason Miller","email":"jason@developit.ca"},"license":"MIT","devDependencies":{"babel-jest":"^21.2.0","babel-loader":"^7.1.2","babel-plugin-transform-react-jsx":"^6.24.1","babel-polyfill":"^6.26.0","babel-preset-env":"^1.6.1","babel-preset-stage-0":"^6.24.1","bundlesize":"^0.15.3","chai":"^4.1.2","documentation":"^4.0.0","eslint":"^4.12.1","eslint-config-developit":"^1.1.1","jest":"^21.2.1","karma":"^2.0.0","karma-chai-sinon":"^0.1.5","karma-chrome-launcher":"^2.2.0","karma-mocha":"^1.3.0","karma-mocha-reporter":"^2.2.5","karma-sourcemap-loader":"^0.3.7","karma-webpack":"^2.0.9","microbundle":"^0.3.1","mocha":"^4.1.0","npm-run-all":"^4.1.2","sinon":"^4.1.6","sinon-chai":"^2.14.0","strip-json-comments-cli":"^1.0.1","unistore":"^3.0.3","webpack":"^3.10.0","workerize-loader":"^1.0.1"},"peerDependencies":{"unistore":"*"},"bugs":{"url":"https://github.com/developit/stockroom/issues"},"homepage":"https://github.com/developit/stockroom#readme","_id":"stockroom@1.0.0","_npmVersion":"5.5.1","_nodeVersion":"8.9.2","_npmUser":{"name":"developit","email":"jason@developit.ca"},"dist":{"integrity":"sha512-TcP8Oib/rgBCUN4otvZ+hTZpua0JCaOrAoODeYFgKlF0NG5G9gHv/8BrJicQzyogYYgB1Q4l0vEYJYgx755IfQ==","shasum":"cbbaa01739320c5b616b7100f756a4d489c06365","tarball":"https://registry.npmjs.org/stockroom/-/stockroom-1.0.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICa3hp7cTHk1oAfhB7edKO95wEUDfkDIUlvSwReWt/USAiAgHhYW8mPGtjbim3/4e8cX/pn3Hbxf3qmPaUMryw35zQ=="}]},"maintainers":[{"name":"developit","email":"jason@developit.ca"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/stockroom-1.0.0.tgz_1516302913325_0.9491110998205841"}},"1.0.1":{"name":"stockroom","version":"1.0.1","description":"Offload your store management to a worker.","source":"src/index.js","module":"dist/stockroom.es.js","main":"dist/stockroom.js","umd:main":"dist/stockroom.umd.js","typings":"index.d.ts","scripts":{"build":"npm-run-all --silent bundle size docs","bundle":"microbundle src/index.js -o dist/stockroom.js && microbundle src/inline.js -o inline/index.js && microbundle src/worker.js -o worker/index.js","size":"strip-json-comments --no-whitespace dist/stockroom.js | gzip-size && bundlesize","docs":"documentation readme src/*.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 test && npm run bundle && karma start test/karma.conf.js --single-run","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","globals":{"PRERENDER":0},"rules":{"prefer-rest-params":0,"jest/valid-expect":0,"react/display-name":0}},"bundlesize":[{"path":"dist/stockroom.js","maxSize":"1kb"},{"path":"worker/index.js","maxSize":"1kb"},{"path":"inline/index.js","maxSize":"300b"}],"files":["src","dist","inline","worker"],"keywords":["preact","unistore","state machine","worker","threads","redux"],"repository":{"type":"git","url":"git+https://github.com/developit/stockroom.git"},"author":{"name":"Jason Miller","email":"jason@developit.ca"},"license":"MIT","devDependencies":{"babel-jest":"^22.1.0","babel-loader":"^7.1.2","babel-plugin-transform-react-jsx":"^6.24.1","babel-polyfill":"^6.26.0","babel-preset-env":"^1.6.1","babel-preset-stage-0":"^6.24.1","bundlesize":"^0.15.3","chai":"^4.1.2","documentation":"^4.0.0","eslint":"^4.16.0","eslint-config-developit":"^1.1.1","jest":"^22.1.4","karma":"^2.0.0","karma-chai-sinon":"^0.1.5","karma-chrome-launcher":"^2.2.0","karma-mocha":"^1.3.0","karma-mocha-reporter":"^2.2.5","karma-sourcemap-loader":"^0.3.7","karma-webpack":"^2.0.9","microbundle":"^0.4.3","mocha":"^4.1.0","npm-run-all":"^4.1.2","sinon":"^4.2.2","sinon-chai":"^2.14.0","strip-json-comments-cli":"^1.0.1","unistore":"^3.0.4","webpack":"^3.10.0","workerize-loader":"^1.0.1"},"peerDependencies":{"unistore":"*"},"gitHead":"0c99699ed38c3cf993e4f08d489da9fa774e5e52","bugs":{"url":"https://github.com/developit/stockroom/issues"},"homepage":"https://github.com/developit/stockroom#readme","_id":"stockroom@1.0.1","_npmVersion":"5.6.0","_nodeVersion":"8.9.2","_npmUser":{"name":"developit","email":"jason@developit.ca"},"dist":{"integrity":"sha512-TS+e+5GTDjwdDHqk6p6A/VJYLXa5ByXsB2I6c+RmTfqO94pDQiNw7JWFqUmo4+eaTZwHZ460Q9yL9+GpfrbOoQ==","shasum":"81e88b6a5b52cc0b2a212c2daf3c31f7ecbe7b26","tarball":"https://registry.npmjs.org/stockroom/-/stockroom-1.0.1.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGNWwQtvve8xajamovGLMoufcwkH3n6jSChwJOLWvqf3AiEA70jgpcT/z8F8jTvbKJAL4jklEpI0zpMHy0byYsKM54o="}]},"maintainers":[{"name":"developit","email":"jason@developit.ca"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/stockroom-1.0.1.tgz_1517253636997_0.8156697687227279"}}},"readme":"<p align=\"center\">\n  <img src=\"https://i.imgur.com/352HMex.jpg\" width=\"1000\" alt=\"stockroom\">\n  <br>\n  <img src=\"https://i.imgur.com/mSDvn6Z.jpg\" width=\"1000\" alt=\"stockroom\">\n  <br>\n  <a href=\"https://www.npmjs.org/package/stockroom\"><img src=\"https://img.shields.io/npm/v/stockroom.svg?style=flat\" alt=\"npm\"></a> <a href=\"https://travis-ci.org/developit/stockroom\"><img src=\"https://travis-ci.org/developit/stockroom.svg?branch=master\" alt=\"travis\"></a>\n</p>\n\n# Stockroom\n\n> Offload your store management to a worker.\n\nStockroom seamlessly runs a [Unistore] store (and its actions) in a Web Worker, setting up optimized bidirectional sync so you can also use & subscribe to it on the main thread.\n\n- **Easy** same API as [unistore] - a simple add-on\n- **Opt-in** centralized actions with the option of running on the main thread\n- **Convenient** action selector shorthand - no action creator needed for simple actions\n- **Gracefully degrades** - feature-detect Worker support and fall back to `stockroom/inline`\n\n## Table of Contents\n\n- [Install](#install)\n- [Usage](#usage)\n- [API](#api)\n- [License](#license)\n\n## Install\n\nStockroom requires that you install [unistore](https://github.com/developit/unistore) (300b) as a peer dependency.\n\n```sh\nnpm install --save unistore stockroom\n```\n\n## Usage\n\nWe'll have two files: `index.js` and `worker.js`.  The first is what we import from our app, so it runs on the main thread - it imports our worker (using [worker-loader] or [workerize-loader]) and passes it to Stockroom to create a store instance around it.\n\n**index.js**:\n\n```js\nimport createStore from 'stockroom'\nimport StoreWorker from 'worker-loader!./worker'\n\nlet store = createStore(new StoreWorker())\n\nlet increment = store.action('increment')\nstore.subscribe(console.log)\n\n// Let's run a registered \"increment\" action in the worker.\n// This will eventually log a state update to the console - `{ count: 1 }`\nincrement()\n```\n\nThe second file is our worker code, which runs in the background thread. Here we import Stockroom's worker-side \"other half\", `stockroom/worker`.  This function returns a store instance just like `createStore()` does in [Unistore], but sets things up to synchronize with the main/parent thread.  It also adds a `registerActions` method to the store, which you can use to define globally-available actions for that store.  These actions can be triggered from the main thread by invoking `store.action('theActionName')` and calling the function it returns.\n\n**worker.js**:\n\n```js\nimport createStore from 'stockroom/worker'\n\nlet store = createStore({\n  count: 0\n})\n\nstore.registerActions( store => ({\n  increment: ({ count }) => ({ count: count+1 })\n}) )\n\nexport default store  // if you wish to use `stockroom/inline`\n```\n\n### API\n\n<!-- Generated by documentation.js. Update this documentation by updating the source code. -->\n\n#### module:stockroom\n\nThe main stockroom module, which runs on the main thread.\n\n##### createStore\n\nGiven a Web Worker instance, sets up RPC-based synchronization with a WorkerStore running within it.\n\n**Parameters**\n\n- `worker` **[Worker](https://developer.mozilla.org/docs/Web/JavaScript)** An instantiated Web Worker (eg: `new Worker('./store.worker.js')`)\n\n**Examples**\n\n```javascript\nimport createStore from 'stockroom'\nimport StoreWorker from 'worker-loader!./store.worker'\nlet store = createStore(new StoreWorker)\n```\n\nReturns **Store** synchronizedStore - a mock unistore store instance sitting in front of the worker store.\n\n#### module:stockroom/inline\n\nUsed to run your whole store on the main thread.\nUseful non-worker environments or as a fallback.\n\n##### createInlineStore\n\nFor SSR/prerendering, pass your exported worker store through this enhancer\n to make an inline synchronous version that runs in the same thread.\n\n**Parameters**\n\n- `workerStore` **WorkerStore** The exported `store` instance that would have been invoked in a Worker\n\n**Examples**\n\n```javascript\nlet store\nif (SUPPORTS_WEB_WORKERS === false) {\n\tlet createStore = require('stockroom/inline')\n\tstore = createStore(require('./store.worker'))\n}\nelse {\n\tlet createStore = require('stockroom')\n\tlet StoreWorker = require('worker-loader!./store.worker')\n\tstore = createStore(new StoreWorker())\n}\nexport default store\n```\n\nReturns **Store** inlineStore - a unistore instance with centralized actions\n\n#### module:stockroom/worker\n\nThe other half of stockroom, which runs inside a Web Worker.\n\n##### createWorkerStore\n\nCreates a unistore instance for use in a Web Worker that synchronizes itself to the main thread.\n\n**Parameters**\n\n- `initialState` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Initial state to populate (optional, default `{}`)\n\n**Examples**\n\n```javascript\nimport createWorkerStore from 'stockroom/worker'\nlet initialState = { count: 0 }\nlet store = createWorkerStore(initialState)\nstore.registerActions({\n\tincrement(state) {\n\t\treturn { count: state.count + 1 }\n\t}\n})\n```\n\nReturns **WorkerStore** workerStore (enhanced unistore store)\n\n#### freeze\n\nQueue all additional processing until unfrozen.\nfreeze/unfreeze manages a cumulative lock:\nunfreeze must be called as many times as freeze was called in order to remove the lock.\n\n#### unfreeze\n\nRemove a freeze lock and process queued work.\n\n### License\n\n[MIT License](https://oss.ninja/mit/developit) © [Jason Miller](https://jasonformat.com/)\n\n[unistore]: https://github.com/developit/unistore\n\n[preact]: https://github.com/developit/preact\n\n[worker-loader]: https://github.com/webpack-contrib/worker-loader\n\n[workerize-loader]: https://github.com/developit/workerize-loader\n","maintainers":[{"name":"developit","email":"jason@developit.ca"}],"time":{"modified":"2022-05-18T18:23:14.210Z","created":"2018-01-18T19:15:13.453Z","1.0.0":"2018-01-18T19:15:13.453Z","1.0.1":"2018-01-29T19:20:37.079Z"},"homepage":"https://github.com/developit/stockroom#readme","keywords":["preact","unistore","state machine","worker","threads","redux"],"repository":{"type":"git","url":"git+https://github.com/developit/stockroom.git"},"author":{"name":"Jason Miller","email":"jason@developit.ca"},"bugs":{"url":"https://github.com/developit/stockroom/issues"},"license":"MIT","readmeFilename":"README.md"}