structures. • This means that all methods don’t alter an existing structure, but return a brand new structure. • This is made efficient by structural sharing (a.k.a. graph magic).
of the redux system • Most recently, a module popped up in an application that lets the server directly send redux commands to all connected clients. • This means that the server had direct knowledge of how the frontend is structured, which is a general no-no. • Replacing redux with something that has a more targeted use and more specific documentation would go a long way to reducing these kinds of antipatterns.
has been, unfortunately, very low • This is a general issue and needs to be tackled one brick at a time • Sharing code for a data store is a good a place as any to start
the place of redux • Make it easy to integrate with existing Components and general enough to integrate with any future system • Make it clear what data can be taken from the store and what events will transform the store • Make the system as reusable as possible
• Just as in redux, events trigger an update to the data. • After any change, a list of “subscriptions” is calculated. • If the value of a subscription changes: • Re-render any components that depend on that subscription. Events Update Store Subs. Render
re-frame are subscribe, dispatch, register event, and register subscription • I chose to define each of these as part of a generic interface that depends on the concept of a “notifiable”, which will be “told” when the subscription it depends on has changed
reference to the “notifiable” that is subscribing to the value. • That INotifiable is then added to a dictionary of subscribers associated with the name of the subscription.
event name and a variable amount of arguments to apply. • After each dispatch, the value for each subscription is recalculated, and any INotifiables that depend on subscription values that have changed are told that a change has occured
and put into a dictionary with the key being the name of the subscription • It is safe to memoize the function because we are assuming that it is pure regardless • This has the nice benefit of making the calculation of new subscription values very fast if the value hasn’t changed
generic data store work with React components, all that was needed was to subclass and override subscribe. • The new subscribe wraps any React components passed to it in an INotifiable that causes a re-render whenever it is notified of a change.
store it is then sufficient to call subscribe directly from the render function. • Because subscriptions are stored in a dictionary, it is safe to call subscribe multiple times.