EOSIO / demux-js-eos

Demux-js Action Reader implementations for EOSIO blockchains
MIT License
39 stars 17 forks source link

How to declare Global Variable in Demux? #78

Closed johnworthley closed 5 years ago

johnworthley commented 5 years ago

Hi! I am having trouble declaring a global variable in Demux which doesn't reset after effecting every EOS Transfer. Is there a way to declare this within the Updaters folder?

jeffreyssmith2nd commented 5 years ago

The Updaters/Effects have a context parameter on their apply/run functions that can be used to pass information through to each of them.

https://github.com/EOSIO/demux-js/blob/develop/src/interfaces.ts#L62

If that isn't what you're looking for, if you can explain your use case a bit more that may help figure out what you need.

johnworthley commented 5 years ago

Considering storing the global variable on eosio on a memo transaction to be later retrieved when necessary

flux627 commented 5 years ago

The point of the Action Handler is to persist state accumulatively, which should be accessible between each action / block. If you need to temporarily persist data between each action in the same block, you can mutate the context object and it will persist between actions / effects.