What do you think about XState, which is actor model inspired state handling often used on the front-end?
Ideally, I imagine it would be nice with Niladic Components (no props), so React could be a dumb View layer, and simply handle all state separately in XState…
isn't pre-emptively scheduled. Typically a process is blocked at a receive() (or any other blocking call) waiting for the next message and even if it isn't the scheduler will suspend it after it consumes it's reductions.
None of this is feasible in single threaded/event loop based JavaScript but it points to the possibility of tying process scheduling to message delivery:
A "processing scope" (replacing "actor") only gets processing control when it receives a message (with some exceptions; the message would likely be arrive via a subscription). To be well behaved it has to break up large tasks into phases which it initiates by sending a message to itself at the end of the current phase.
To interact with other "processing scopes" is has to send a message. However there is no immediate response (the message goes to the end of the delivery queue). If there is a response it will be received later at which point in time it can be processed (so the processing scope state has to reflect this "in progress interaction" - the equivalent to a "function call (returning a value)" to a separate processing scope).
So the basic functionality needed for a processing scope is a way to receive messages so it has something to do, and a way to send messages so it can collaborate with other processing scopes. For that to work the message router/scheduler needs to support a few things:
The entire system is built around postMessage(). For the purpose of discussion lets call a Window or Worker a "processing node".
Each node
routes messages (i.e. has to manage routing data)
messages to the local processing scopes are put on the delivery queue
messages to processing scopes managed by another node are immediately posted to the nearest node.
schedules processing by
delivering a single message to the local processing scope from the head of the delivery queue provided there is enough time left in the current processing slice
returning control to the event loop when the current processing slice is exhausted.
when the delivery queue is empty use queueMicrotask() to start the next processing slice when a message is placed on the delivery queue arriving from another node or a general send (e.g. caused by an input event).
Now a system like this is inherently asynchronous—so in my judgement has little to no chance to be adopted by the JavaScript community given how relieved everybody was when async/await was introduced.
In terms of the PolymerLabs MessageStore I would be concerned that forcing messages through IndexedDB would slow things down unnecessarily.
props will be involved whenever you use a component more than once on the same page to represent separate business entities.
As I said before
I need to mention that the identity of Component is not always the same as the identity of Instance of Component. That's why in some framework you need to specify the key.
although there are no real key here but different update props are passed to identify different entities. In certain degree it's the mismatch between UI and application proved again.
and the solution is fairly simple... encapsulate High Order Component
although it's not necessary to involve any architecture decision, I'm placing the kairo's solution here
const[External,ExternalImpl]=createConcreteConcern('External',function*(){const[leftValue,setLeft]=yield*State(0);const[rightValue,setRight]=yield*State(0);return{leftValue,rightValue,setLeft,setRight}});// a shortcut of `createConcern` with a default implementationconstValue=UI(function*({value,setValue}:{value:Cell<number>,setValue:Setter<number>}){constonChange=e=>setValue(e.target.value);returnComponent((_,$)=>(<span><inputvalue={$(value)}onChange={onChange}/></span>));});constApp=UI(function*(){const{leftValue,rightValue,setLeft,setRight}=yield*External;constLeft=yield*Include(Value.withProps({value:leftValue,setValue:setLeft}));constRight=yield*Include(Value.withProps({value:rightValue,setValue:setRight}));returnComponent((_,$)=>(<divclassName="App"><h1>Totals</h1><Left/><Right/>
total is {$(leftValue)+$(rightValue)}</div>));});
notably I made Value fully controlled because it's unnecessary to have a local state as there is already a source of truth.
@peerreynders regarding Actor-Model you mentioned in this thread, you might be interested in this lib: reatom.dev/ (but it also relevant to the overall discussion)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
What do you think about XState, which is actor model inspired state handling often used on the front-end?
Ideally, I imagine it would be nice with Niladic Components (no props), so React could be a dumb View layer, and simply handle all state separately in XState…
See my comment here
Expressed roughly in JavaScript-like syntax an Erlang process is at its simplest
Of course JavaScript
receive()
(or any other blocking call) waiting for the next message and even if it isn't the scheduler will suspend it after it consumes it's reductions.None of this is feasible in single threaded/event loop based JavaScript but it points to the possibility of tying process scheduling to message delivery:
So the basic functionality needed for a processing scope is a way to receive messages so it has something to do, and a way to send messages so it can collaborate with other processing scopes. For that to work the message router/scheduler needs to support a few things:
Now a system like this is inherently asynchronous—so in my judgement has little to no chance to be adopted by the JavaScript community given how relieved everybody was when async/await was introduced.
In terms of the PolymerLabs MessageStore I would be concerned that forcing messages through IndexedDB would slow things down unnecessarily.
Is postMessage slow?
But thanks for asking …
Note what is going on in his niladic solution:
He is failing to extract the variation of two near identical components in order to preserve their "niladic" property
props
will be involved whenever you use a component more than once on the same page to represent separate business entities.As I said before
although there are no real
key
here but differentupdate
props are passed to identify different entities. In certain degree it's the mismatch between UI and application proved again.and the solution is fairly simple... encapsulate High Order Component
although it's not necessary to involve any architecture decision, I'm placing the
kairo
's solution herenotably I made
Value
fully controlled because it's unnecessary to have a local state as there is already a source of truth.@peerreynders regarding Actor-Model you mentioned in this thread, you might be interested in this lib: reatom.dev/ (but it also relevant to the overall discussion)