Custom AsyncSystem
Last updated
Was this helpful?
Last updated
Was this helpful?
ActiveJS exposes an class that can be used to create customized like .
One limitation of is that it doesn't let you change the type of used by it.
With you can create your own AsyncSystem like Systems and use any type of Unit you want as queryUnit
, dataUnit
and errorUnit
.
AsyncSystemBase can be utilized in two ways,
Instead of creating an instance of where the are created internally, you can create the Units yourself and pass them to the directly.
When using a custom AsyncSystem, directly or by extending, there are a few things that you should keep in mind, to get the expected results.
If you don't want to create Units every time you want to create a custom AsyncSystem, you can extend the base class and do the same thing that does, abstract away the Unit creation in the extended class and only accept typings through generics. This will allow you to be more efficient while still staying flexible.
Example: Create a custom AsyncSystem that uses as queryUnit
, as dataUnit
and as errorUnit
.
uses because it's very permissive in what it accepts as its value while other Units only allow a specific data type, this difference in behavior might cause a hung state, for example, if we use a as the dataUnit
and we try to dispatch an array
value, it will get ignored and any observer expecting a new value wouldn't receive it. Additionally, pendingUnit
wouldn't be updated automatically. (i.e. It'll stay true
until successful data or error dispatch)
To mitigate this problem, when using a non- as a dataUnit
or errorUnit
, ensure that the value being dispatched is valid and will be dispatched. Every Unit has a wouldDispatch
method for exactly this kind of scenario.