All Projects → dai-shi → Redux In Worker

dai-shi / Redux In Worker

Licence: mit
Entire Redux in Web Worker

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Redux In Worker

Post Me
📩 Use web Workers and other Windows through a simple Promise API
Stars: ✭ 398 (+136.9%)
Mutual labels:  web-worker, worker
Workerize Loader
🏗️ Automatically move a module into a Web Worker (Webpack loader)
Stars: ✭ 2,135 (+1170.83%)
Mutual labels:  web-worker, worker
Remote Web Streams
Web streams that work across web workers and iframes.
Stars: ✭ 26 (-84.52%)
Mutual labels:  web-worker, worker
Alloy Worker
面向事务的高可用 Web Worker 通信框架
Stars: ✭ 349 (+107.74%)
Mutual labels:  web-worker, worker
Greenlet
🦎 Move an async function into its own thread.
Stars: ✭ 4,511 (+2585.12%)
Mutual labels:  web-worker, worker
Hamsters.js
100% Vanilla Javascript Multithreading & Parallel Execution Library
Stars: ✭ 517 (+207.74%)
Mutual labels:  web-worker, worker
Stockroom
🗃 Offload your store management to a worker easily.
Stars: ✭ 1,745 (+938.69%)
Mutual labels:  web-worker, worker
Pokemon63
「みんなの63 - スクリーンショットから自動解析できるポケモンの選出投稿サイト」のソースコード
Stars: ✭ 107 (-36.31%)
Mutual labels:  web-worker
Aint Queue
🚀 An async-queue library built on top of swoole, flexable multi-consumer, coroutine supported. 基于 Swoole 的一个异步队列库,可弹性伸缩的工作进程池,工作进程协程支持。
Stars: ✭ 143 (-14.88%)
Mutual labels:  worker
Threads.js
🧵 Make web workers & worker threads as simple as a function call.
Stars: ✭ 1,328 (+690.48%)
Mutual labels:  web-worker
Webworker Promise
Promise based wrapper for webworkers
Stars: ✭ 77 (-54.17%)
Mutual labels:  web-worker
Pwa Cookbook
personally website
Stars: ✭ 107 (-36.31%)
Mutual labels:  worker
Beaver
Android MVVM + Dagger 2 (Hilt) + JetPack project template
Stars: ✭ 144 (-14.29%)
Mutual labels:  worker
Webworkify Webpack
launch a web worker at runtime that can require() in the browser with webpack
Stars: ✭ 105 (-37.5%)
Mutual labels:  web-worker
Vue In Web Worker
Vue.js in Web Worker
Stars: ✭ 149 (-11.31%)
Mutual labels:  web-worker
Service
Android Service Examples
Stars: ✭ 91 (-45.83%)
Mutual labels:  worker
Workly
A really simple way to move a function or class to a web worker. 🏋️‍♀️→ 😄
Stars: ✭ 1,848 (+1000%)
Mutual labels:  web-worker
Vuex Search
Vuex binding for client-side search with indexers and Web Workers 📗🔍
Stars: ✭ 147 (-12.5%)
Mutual labels:  web-worker
Activejob Retry
Automatic retries for ActiveJob
Stars: ✭ 138 (-17.86%)
Mutual labels:  worker
Toolkit
Collection of useful patterns
Stars: ✭ 137 (-18.45%)
Mutual labels:  worker

redux-in-worker

Build Status npm version bundle size

Entire Redux in Web Worker

Introduction

Inspired by React + Redux + Comlink = Off-main-thread.

This is still an experimental project. Please give us a feedback to make it stable.

Some key points are:

  • It only sends "diffs" from the worker thread to the main thread.
  • All Objects in a state tree keep the ref equality.
  • It can run middleware in the worker thread. (only non-DOM middleware #2)
  • No async functions are involved.
  • No proxies are involved.

Install

npm install redux-in-worker

Usage

store.worker.js:

import { createStore } from 'redux';
import { exposeStore } from 'redux-in-worker';

const initialState = { count: 0 };
const reducer = (state = initialState, action) => {
  switch (action.type) {
    case 'increment':
      return { ...state, count: state.count + 1 };
    case 'decrement':
      return { ...state, count: state.count - 1 };
    default:
      return state;
  }
};

const store = createStore(reducer);

exposeStore(store);

app.js:

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider, useDispatch, useSelector } from 'react-redux';
import { wrapStore } from 'redux-in-worker';

const initialState = { count: 0 };
const worker = new Worker('./store.worker', { type: 'module' });
const store = wrapStore(worker, initialState);

const Counter = () => {
  const dispatch = useDispatch();
  const count = useSelector(state => state.count);
  return (
    <div>
      count: {count}
      <button type="button" onClick={() => dispatch({ type: 'increment' })}>+1</button>
      <button type="button" onClick={() => dispatch({ type: 'decrement' })}>-1</button>
    </div>
  );
};

const App = () => (
  <Provider store={store}>
    <Counter />
    <Counter />
  </Provider>
);

ReactDOM.render(<App />, document.getElementById('app'));

Examples

The examples folder contains working examples. You can run one of them with

PORT=8080 npm run examples:01_minimal

and open http://localhost:8080 in your web browser.

Blogs

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