mobxprovides the tool to do that, and it is almost indistinguishable from magic.
renderViewagain to refresh:
renderViewmanually, we'd like it to be called automatically when we modify the object, like so:
mobxintroduces two magic functions:
autorun, so it gets re-executed when
objin the provided console, and see the view changing.
autorun, the framework handles it. But the idea is the same, modify an object, and the components that uses the object would automatically re-render.
solar.development.jsoninto the project:
myTokeninstances are initialized with two global constants:
Storeis an observable object. If the
totalSupplyproperty changes, the React component that uses it would update.
updateTotalSupplyto get the total supply. The simplified
this.totalSupply, the view that uses it would get re-rendered. Specifically, this chunk of JSX:
Mintevent so we can update the total supply immediately if somebody minted additional tokens. The simplified code:
Transferevents, and does something when notified:
Mint: update the total supply.
Transfer: add the transfer event to an array, so we can display it in the UI.
Transferevent should show up in the UI:
mintTokensmethod tracks the mint transactions that had been made, and updates the UI as the transactions progress through the various stages of their lifecycles.
txRecord. The second half updates the txRecord, which in turn triggers views to update.