Comments (4)
A toy example using the method under Alternatives
might help people better understand your proposal.
from microstates.
@mharris717 updated, see this makes sense.
from microstates.
We could fix the problem of root
being verbose by using a chaining syntax for Effect
itself:
Effect() // implicit path [], implicit effect is no-op x => x
.do(repaint)
.do(currentReference)
.do(bluetoothController)
.doAt('scan', scanController)
There are a couple things to consider how to handle effects.
Enumeration
We have to be able to specify effects for arrays and objects for which we won't know the path of ahead of time. An example is the peripherals, how do we register an effect over an entire list of peripherals
Structure
Effects need to be organized in a tree, and evaluated from the top to the bottom. For example, if we have an effect that is waiting to run on a peripheral, but we turn bluetooth off, which removes all the peripherals, then we need to do two things:
- not run any pending effects on the list of peripherals
- run any teardown on each effect that is active and associated with one of the peripherals being removed.
Intermediate States (optional, but nice to have)
One thing I've noticed is that async operations generally have a state machine that looks like roughly.
- NotDoingTheThing
- RequestHasBeenIssuedToDoTheThing
- NowDoingTheThing
- RequestIssuedToNotDoTheThingAnymore
- NotDoingTheThing (Same state as 1)
In the case of the scan, these are
- Idle
- Activating
- Active
- Deactivating
- Idle
The Activating
and Deactivating
states exist only to represent the transition between Idle
and Active
and while this is correct and necessary, it would be nice to be able to factor them out somehow in order to avoid doubling the number of states needed to represent every since async transition.
I was thinking something like this
import { each } from '@microstates/effects';
const scanController = each({ isOn: true, scan: each({ isActivating: true })}, *(scan) => {
noble.startScanning();
yield scan.activate();
}).each({}, scan: each({isDeactivating: true}), *(scan) => {
noble.stopScanning();
yield scan.deactivate();
});
The reason we yield is to indicate that we're performing a state transition and so there is a new top level state, so we don't need to run any of the subsequent effects down the tree, but should start again matching from the top.
from microstates.
This is going to be superseded by http://github.com/thefrontside/effection
from microstates.
Related Issues (20)
- Typescript types definition files HOT 4
- Handling onChange for Number Type HOT 8
- Remove `parameterized` functionality and replace with simple functions
- Proposal for auto publish process HOT 5
- "invalid typeclass name" error when using with Razzle HOT 5
- ArrayType#sort should pass microstates to comparer instead of value
- Quest: TypeScript support
- An in-range update of mocha is breaking the build 🚨 HOT 8
- An in-range update of rollup is breaking the build 🚨 HOT 81
- Control child Microstate creation HOT 13
- Export `query()` function
- Add `flatMap` method to query.
- add `concat` method to query
- General usage feedback (naming things, type checks) HOT 4
- Publishing to NPM with branch as tag HOT 4
- from() examples with objects don't work HOT 5
- Is this library stable? HOT 2
- Update logo for social preview HOT 2
- Can microstates be used in the browser? (IE11)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from microstates.