Giter Club home page Giter Club logo

redux-worker's Introduction

redux-worker

Redux-Worker is a middleware for Redux.

It helps you build multi-threaded JavaScript applications by moving your reducer into a Web Worker. It also provides a simple API for you to register tasks to be executed in the web worker outside of Redux.

Check out the demo: (Right) Performing synchronous calculations on a separate worker thread, without blocking the main thread.

Documentation

See the API docs.

Inspiration

The Web Workers API has been around for several years now, but we have yet to see much adoption from the community. I think this is mostly due to setup complexity, asynchronous message passing, and the need to think in a different context (one can't share functions/references between Worker threads).

It used to be difficult to conceptualize how to harness the power of Web Workers in an MVC application due to the constraint above. However, Redux has changed the way we think about building applications in JavaScript. Its three principles make it easy to move your app logic into a separate task.

If you are not familiar with web workers, I'd recommend starting with the following materials.

Limitations

Redux-Worker helps you use web workers in your Redux applications. It does so by enhancing your Redux store with:

  • A dispatcher that posts messages to a worker thread
  • A replacement reducer that listens to messages from a Web Worker and then updates state
  • A mechanism to register and execute tasks in a Web Worker using the dispatcher, which returns a promise that will resolve when the task completes.

It spawns just one Web Worker instance, so don't give it more credit than it deserves. It does not provide an interface for spawning multiple workers and balancing work between them: this is a much more complicated problem that Redux-Worker is not attempting to solve.

Demos

To run a demo locally, cd into a folder in the demo directory, and then:

npm i
npm run watch

redux-worker's People

Contributors

andarist avatar chikeichan avatar sdtsui avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.