{"library":"redux-bundler-worker","title":"Redux Bundler Web Worker Utilities","description":"redux-bundler-worker provides utilities for offloading an entire redux-bundler application into a Web Worker, allowing the main thread to focus solely on rendering. It achieves this by offering a `getStoreProxy` function for the main thread, which mimics the redux-bundler store API, and a `setUpWorker` function for the worker thread to initialize the actual redux-bundler store. This approach aims to demonstrate a feature-complete mechanism for isolating Redux logic. The current stable version, `0.0.3`, is explicitly stated as being \"largely for demonstration purposes\" and not shipped in any production applications by its author. As such, it does not have a clear release cadence and should be considered experimental. Its key differentiator is the complete isolation of Redux state management and logic within a worker, reducing main thread overhead.","language":"javascript","status":"abandoned","last_verified":"Tue Apr 21","install":{"commands":["npm install redux-bundler-worker"],"cli":null},"imports":["import { getStoreProxy } from 'redux-bundler-worker'","import { setUpWorker } from 'redux-bundler-worker'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"/* --- main.js (Main Thread) --- */\nimport { render, h } from 'preact';\nimport { Provider } from 'redux-bundler-preact';\nimport { getStoreProxy } from 'redux-bundler-worker';\n\n// A dummy RootComponent for demonstration\nconst RootComponent = ({ children }) => h('div', null, h('h1', null, 'App Running in Worker'), children);\n\n// Create the Web Worker instance, pointing to your bundled worker script\n// Ensure '/build/worker.js' is correctly served by your web server/bundler\nconst worker = new Worker('/build/worker.js', { type: 'module' });\n\n// Get a store proxy that mimics the redux-bundler store API\n// All actions dispatched and selectors called on this proxy will be marshalled to the worker\nconst storeProxy = getStoreProxy(worker);\n\n// Render your Preact app, passing the store proxy to the Provider\nrender(\n  h(Provider, { store: storeProxy }, h(RootComponent)),\n  document.getElementById('app-root')\n);\n\nconsole.log('Main thread initialized with worker-proxied Redux store.');\n\n/* --- worker.js (Web Worker Thread) --- */\nimport { composeBundles } from 'redux-bundler';\nimport { setUpWorker } from 'redux-bundler-worker';\n\n// Define a simple Redux Bundler bundle inside the worker\nconst appBundle = {\n  name: 'app',\n  reducer: (state = { count: 0 }, action) => {\n    if (action.type === 'INCREMENT') {\n      return { ...state, count: state.count + 1 };\n    }\n    return state;\n  },\n  doIncrement: () => ({ dispatch }) => {\n    dispatch({ type: 'INCREMENT' });\n  },\n  selectCount: (state) => state.app.count,\n};\n\n// Compose the bundles to create the main Redux Bundler store function\nconst getWorkerStore = (initialData = {}) => composeBundles(appBundle)(initialData);\n\n// Set up the worker, passing the function that returns the composed store\nsetUpWorker(getWorkerStore);\n\nconsole.log('Web Worker initialized with Redux Bundler store.');\n\n// Example of interacting from the main thread after setup (e.g., in browser console)\n// window.store = storeProxy; // expose for debugging\n// storeProxy.doIncrement();\n// storeProxy.selectCount();","lang":"javascript","description":"This example demonstrates how to set up `redux-bundler-worker` by initializing a Web Worker in the main thread and establishing a proxied Redux store for communication. It shows how to use `getStoreProxy` in the main thread with a UI library like Preact and `setUpWorker` inside the Web Worker to host the actual `redux-bundler` instance, including a basic bundle with actions and selectors.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}