withWorkerStore function #

The withWorkerStore function extends a component and makes working with stores in web workers easier.

import { html, renderer } from 'https://cdn.skypack.dev/@ficusjs/renderers@3/htm'
import { createCustomElement, withWorkerStore } from 'https://cdn.skypack.dev/ficusjs@3'

// import the worker
import { worker } from './worker-store.js'

withWorkerStore(worker, {
increment () {
this.dispatch('increment', this.state.count + 1)
render () {
return html`<button type="button" onclick=${this.increment}>Increment</button>`

The withWorkerStore function provides a this.state property within the component as well as a this.dispatch() method for invoking store actions.
It also makes the component reactive to store changes as well as handling automatic store subscriptions based on the component lifecycle hooks.
It will also refresh computed getters when store state changes.

dispatch method #

The dispatch method can be called to invoke an action in the store.

this.dispatch('increment', this.state.count + 1)

The dispatch method takes two parameters:

  • actionKey is the string name of your action
  • payload is the data that you want to pass along to your action