How do Raj and Redux compare performance wise?
Raj is faster theoretically. In Redux you have N reducers that need to be iterated, in Raj you have a single update which can call sub graph updates (log N). Redux also can have multiple subscriptions whereas Raj doesn't have any. Looking at code size and the amount of work each project does and the list-vs-tree distribution of work, Raj should be better.
Also since (logic+view+data) assemble into Raj programs, it's easier to code-split and lazy-load. There's no definite story for how to do at in Redux. In Raj, you use raj-spa
where a program can resolve from a promise.
Is there a way to apply Raj to a backend state machine where there is no view?
So view
is mostly for apps with UIs. It is a side-effect that receives the whole state as opposed to plain effects which need portions of state explicitly passed. If you don't need a view, you can think of it like a "window" into the current state. For example, you can have something like tapProgram
which leverages view
to log state changes:
function tapProgram (program, onChange) {
return {
...program,
view (model, dispatch) {
onChange(model)
return program.view(model, dispatch)
}
}
}
Raj can be used as a state machine alone.
The reason view is not optional is because then every HOP would need to do that safety check.
Since view: () => {}
is valid, it's better to just let that be a required function in the interface even if it is only a no-op.
There is the optional done
and the if-exists check on that is tedious.
So tedious that it was important to make raj-subscription
to handle those cases for us automatically.
I'm also not opposed to a raj-viewless
function:
const viewless = program => ({ ...program, view: () => {} })
Or something that wraps the runtime itself. Since it is a choke-point you can stop all view calls with a HOP.