All Projects β†’ developit β†’ Stockroom

developit / Stockroom

πŸ—ƒ Offload your store management to a worker easily.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Stockroom

Alloy Worker
ι’ε‘δΊ‹εŠ‘ηš„ι«˜ε―η”¨ Web Worker ι€šδΏ‘ζ‘†ζžΆ
Stars: ✭ 349 (-80%)
Mutual labels:  web-worker, worker
Hamsters.js
100% Vanilla Javascript Multithreading & Parallel Execution Library
Stars: ✭ 517 (-70.37%)
Mutual labels:  web-worker, worker
Post Me
πŸ“© Use web Workers and other Windows through a simple Promise API
Stars: ✭ 398 (-77.19%)
Mutual labels:  web-worker, worker
Loona
πŸŒ• Application State Management done with GraphQL
Stars: ✭ 270 (-84.53%)
Mutual labels:  flux, state-management
Remote Web Streams
Web streams that work across web workers and iframes.
Stars: ✭ 26 (-98.51%)
Mutual labels:  web-worker, worker
Fluorine
[UNMAINTAINED] Reactive state and side effect management for React using a single stream of actions
Stars: ✭ 287 (-83.55%)
Mutual labels:  flux, state-management
Greenlet
🦎 Move an async function into its own thread.
Stars: ✭ 4,511 (+158.51%)
Mutual labels:  web-worker, worker
RxReduxK
Micro-framework for Redux implemented in Kotlin
Stars: ✭ 65 (-96.28%)
Mutual labels:  flux, state-management
Vue Entity Adapter
Package to maintain entities in Vuex.
Stars: ✭ 20 (-98.85%)
Mutual labels:  flux, state-management
Little State Machine
πŸ“  React custom hook for persist state management
Stars: ✭ 654 (-62.52%)
Mutual labels:  flux, state-management
mini-kotlin
Minimal Flux architecture written in Kotlin.
Stars: ✭ 20 (-98.85%)
Mutual labels:  flux, state-management
Juicr.js
A simple (and tiny <1kb) redux inspired reducer for handling state changes.
Stars: ✭ 102 (-94.15%)
Mutual labels:  flux, state-management
litestate
An ambitiously tiny, gizp ~800b, flux-like library to manage your state
Stars: ✭ 31 (-98.22%)
Mutual labels:  flux, state-management
Grox
Grox helps to maintain the state of Java / Android apps.
Stars: ✭ 336 (-80.74%)
Mutual labels:  flux, state-management
Vuex-Alt
An alternative approach to Vuex helpers for accessing state, getters and actions that doesn't rely on string constants.
Stars: ✭ 15 (-99.14%)
Mutual labels:  flux, state-management
Dutier
The immutable, async and hybrid state management solution for Javascript applications.
Stars: ✭ 401 (-77.02%)
Mutual labels:  flux, state-management
react-evoke
Straightforward action-driven state management for straightforward apps built with Suspense
Stars: ✭ 15 (-99.14%)
Mutual labels:  flux, state-management
vuex-but-for-react
A state management library for React, heavily inspired by vuex
Stars: ✭ 96 (-94.5%)
Mutual labels:  flux, state-management
Reatom
State manager with a focus of all needs
Stars: ✭ 567 (-67.51%)
Mutual labels:  flux, state-management
Freezer
A tree data structure that emits events on updates, even if the modification is triggered by one of the leaves, making it easier to think in a reactive way.
Stars: ✭ 1,268 (-27.34%)
Mutual labels:  flux, state-management

stockroom
stockroom
npm travis

Stockroom

Offload your store management to a worker.

Stockroom 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.

  • Easy same API as unistore - a simple add-on
  • Opt-in centralized actions with the option of running on the main thread
  • Convenient action selector shorthand - no action creator needed for simple actions
  • Gracefully degrades - feature-detect Worker support and fall back to stockroom/inline

Table of Contents

Install

Stockroom requires that you install unistore (300b) as a peer dependency.

npm install --save unistore stockroom

Usage

We'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.

index.js:

import createStore from 'stockroom'
import StoreWorker from 'worker-loader!./worker'

let store = createStore(new StoreWorker())

let increment = store.action('increment')
store.subscribe(console.log)

// Let's run a registered "increment" action in the worker.
// This will eventually log a state update to the console - `{ count: 1 }`
increment()

The 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.

worker.js:

import createStore from 'stockroom/worker'

let store = createStore({
  count: 0
})

store.registerActions( store => ({
  increment: ({ count }) => ({ count: count+1 })
}) )

export default store  // if you wish to use `stockroom/inline`

API

module:stockroom

The main stockroom module, which runs on the main thread.

createStore

Given a Web Worker instance, sets up RPC-based synchronization with a WorkerStore running within it.

Parameters

  • worker Worker An instantiated Web Worker (eg: new Worker('./store.worker.js'))

Examples

import createStore from 'stockroom'
import StoreWorker from 'worker-loader!./store.worker'
let store = createStore(new StoreWorker)

Returns Store synchronizedStore - a mock unistore store instance sitting in front of the worker store.

module:stockroom/inline

Used to run your whole store on the main thread. Useful non-worker environments or as a fallback.

createInlineStore

For SSR/prerendering, pass your exported worker store through this enhancer to make an inline synchronous version that runs in the same thread.

Parameters

  • workerStore WorkerStore The exported store instance that would have been invoked in a Worker

Examples

let store
if (SUPPORTS_WEB_WORKERS === false) {
	let createStore = require('stockroom/inline')
	store = createStore(require('./store.worker'))
}
else {
	let createStore = require('stockroom')
	let StoreWorker = require('worker-loader!./store.worker')
	store = createStore(new StoreWorker())
}
export default store

Returns Store inlineStore - a unistore instance with centralized actions

module:stockroom/worker

The other half of stockroom, which runs inside a Web Worker.

createWorkerStore

Creates a unistore instance for use in a Web Worker that synchronizes itself to the main thread.

Parameters

  • initialState Object Initial state to populate (optional, default {})

Examples

import createWorkerStore from 'stockroom/worker'
let initialState = { count: 0 }
let store = createWorkerStore(initialState)
store.registerActions({
	increment(state) {
		return { count: state.count + 1 }
	}
})

Returns WorkerStore workerStore (enhanced unistore store)

freeze

Queue all additional processing until unfrozen. freeze/unfreeze manages a cumulative lock: unfreeze must be called as many times as freeze was called in order to remove the lock.

unfreeze

Remove a freeze lock and process queued work.

License

MIT License Β© Jason Miller

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].