0.0.3 • Published 6 years ago

redux-bundler-worker v0.0.3

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

redux-bundler-worker

npm.ionpm.ionpm.io

Utilities for running a redux-bundler app inside a worker. Largely for demonstration purposes, I have not shipped any production apps built this way.

But it demonstrates a rather feature-complete mechanism for doing so. Utilizing a worker for the entire redux application and then simply doing rendering in the main thread.

install

npm install redux-bundler-worker

example

In the main thread:

import { render, h } from 'preact'
import { Provider } from 'redux-bundler-preact'
import RootComponent from './components/root'
import { getStoreProxy } from 'redux-bundler-worker'

// init our worker
const worker = new Worker('/build/worker.js')
// pass the worker into getStoreProxy to
// get something that mimics the API of a
// redux store created by redux-bundler
const storeProxy = getStoreProxy(worker)

// render our root component passing the proxy
// as if it were the store to Provider:
render(
  <Provider store={storeProxy}>
    <RootComponent />
  </Provider>,
  document.getElementById('app')
)

In the worker:

import getStore from './src/bundles'
import { setUpWorker } from 'redux-bundler-worker'

// setUpWorker expects a function it can call *with* initial
// data that will return our redux store. This is what is returned
// by calling redux-bundle's `composeBundles` function anyway.
setUpWorker(getStore)

change log

  • 0.0.3 - now handling scroll position restoration
  • 0.0.2 - initial public release

credits

If you like this follow @HenrikJoreteg on twitter.

license

MIT