@beaker73/live-update
v0.1.0
Published
Xrm LiveUpdate tries to simplify 'scripting' for DataVerse Model Driven apps by eliminating all the plumping (getting attributes, attaching and removing event handlers, hiding or showing fields) so we are mostly left with only business logic.
Downloads
1
Readme
Xrm LiveUpdate
Xrm LiveUpdate tries to simplify 'scripting' for DataVerse Model Driven apps by eliminating all the plumping (getting attributes, attaching and removing event handlers, hiding or showing fields) so we are mostly left with only business logic.
It was inspired by react, implementing the business logic as render functions and by home assistant templates and how de detect dependencies on states.
Internal Implementation Abstractions
Memory
The root level abstraction is called memory. During every render you can tell it to 'remember' something. As long as you remember or recall this item on every render it is not forgotten. But as soon as you do not activly recall something it will be forgotten at the end of the render fase. You can provided a callback to be called during forgetting, but not block the forgetting.
Memory is per render function, thus multiple render functions cannot influence each other.
Normally you would not directly use the remember/recall functions yourself, but use the hooks that use this abstraction to be implemented.
useEffect
The first abstraction that is generally used by developers is useEffect. Most other abstractions are based on this one.
useEffect activily remembers the setup and cleanup functions as long as it is called. On first call it executes the provided setup function. On next renders it recognizes the key and does not call the setup again. Until useEffect is not called anymore during a render, and thus it will be forgotten. The forget callback will ensure the cleanup is then called.
This effectly ensure that setup is only called once as long as useCallback is called during every render. And cleanup is called exactly once just after useCallback was not called anymore during render.
useId
use Id returns an id that should be unique, but still returns that same id on every render call.
It works by hasing the stack trace from the start of the render function. Effectivly generate a unique id that is always the same for the same line, but different when you call this method again a second time from a different location.
This Id is often used as a unique memory key by other hooks.
warning: The implementation is dependend on the stacktrace generated by the beaker73/async-context
package. But then again, this whole library effectivly is.