Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Svelte retropropagate stores as a memory registry

$
0
0

is it possible to get a memory registry behavior through Svelte's stores mechanism ? And Having a retroaction looping pattern inside derivation's closure body ?

Imagine a chess game board and its associated toolbars used to populate board for building interactively chess game problems.

Each board's tils and each (possibly nested) toolbuttons are connected to an UIAction store which produces messages like :

{ action: ..., params: ... }...{ action: 'show-toolbox', params: 'toolbox-main' }{ action: 'click-tile', params: 'h8' }{ action: 'click-tile', params: 'a1' }{ action: 'show-toolbox', params: 'point-of-view' }    { action: 'set-pov', params: 'south', forget: 'show-toolbox' }    { action: 'show-toolbox', params: 'point-of-view' }{ action: 'set-pov', params: 'north', forget: 'show-toolbox' }    { action: 'start-game', params: null' }    

The UIActionStore is derived by almost 3 stores (and many more...) so we need a kind of factory function to define ScalableMachineStore (a.k.a "SMS"):

export const ToolBoxStore = createSMS ({    income: UIActionStore,     filter: 'show-toolbox';    strategy: 'stack'})export const POVStore = createSMS ({    income: UIActionStore,     filter: 'show-toolbox';    strategy: 'queue'})export const BoardClickStore = createSMS ({    income: UIActionStore,     filter: 'click-tile';    strategy: 'stack'})    

You could say a work-in-progess example browsing url: [https://colorchess.net](Colored Tactical Helper)

I guess this factory could look like:

export function creatre SMS ({ income, filter, strategy }) {    // used as a stack or as a queue    const memory = []    // current state exposed    const exposed = writable (null)    // to avoid infinite loops    let lock = false    return derived ([income, exposed], ([$income, $exposed]) => {        if (filter === $income.action) {            // THIS IS THE TRICKY PART            $exposed.update ((state) => {                // if lock ???                return $income            })            return $income        } else if ($exposed) {            return $exposed        } else {            return null        }    })}

The errors in the above code:

  • infinitie loops
  • interlocking
  • strange updates

How to fix that ?


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>