GithubHelp home page GithubHelp logo

Comments (4)

mharris717 avatar mharris717 commented on May 27, 2024

A toy example using the method under Alternatives might help people better understand your proposal.

from microstates.

taras avatar taras commented on May 27, 2024

@mharris717 updated, see this makes sense.

from microstates.

cowboyd avatar cowboyd commented on May 27, 2024

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:

  1. not run any pending effects on the list of peripherals
  2. 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.

  1. NotDoingTheThing
  2. RequestHasBeenIssuedToDoTheThing
  3. NowDoingTheThing
  4. RequestIssuedToNotDoTheThingAnymore
  5. NotDoingTheThing (Same state as 1)

In the case of the scan, these are

  1. Idle
  2. Activating
  3. Active
  4. Deactivating
  5. 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.

cowboyd avatar cowboyd commented on May 27, 2024

This is going to be superseded by http://github.com/thefrontside/effection

from microstates.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.