Coder Social home page Coder Social logo

fini's People

Stargazers

 avatar

Watchers

 avatar

fini's Issues

Transition entry and exit effects

Suggested API:

useMachine({
  state1: [
    // effect to run when state is entered
    ({ state, context, dispatch }, event) => { console.log("entered state1") },
    {
      event1: () => "state1",
      event2: () => "state1"
    },
    // effect to run when state is exited
    ({ state, context, dispatch }, event) => { console.log("exited state1") }
  ]
})

Where event is a plain old event object:

{ type: "somethingHappened", payload: 12345 }

Consider prevState in entry and nextState in exit?

Document effect execution order

Support type narrowing for dispatcher events based on current state?

Given the following machine

type M = Machine<{
 state1: State<{
    event1: never
  }>;
  state2: {}
}>

const [state, dispatch] = useMachine<M>(...)

Should attempting the following give an TS error?

if (state.state2) {
  dispatch.event1();
}

Is it possible to also keep all events defined on dispatch when state has not been checked?

Can't infer events without schema

const [state, dispatch] = useMachine({
  state1: {
    event1: "state1"
  }
}, "state1")

dispatch.event1() // Property 'event1' does not exist on type '{}'.ts(2339)

Refactor tests

There is little to no system in the tests. Could be structured in a more meaningful way, and better centered around the various features

Return object instead of tuple from useMachine

Instead of

const [state, dispatch] = useMachine()

would a better API be

const machine = useMachine()

where machine's type is

{
  current: "state1"|"state2";
  context: { ... };
  state1: boolean;
  state2: boolean;
  someEvent: () => void;
  someOtherEvent: (payload: string) => void;
}

or

{
  current: "state1"|"state2";
  context: { ... };
  state1: boolean;
  state2: boolean;
  dispatch: {
    someEvent: () => void;
    someOtherEvent: (payload: string) => void;
  }
}

?

Should be figured out before 1.0

Void event handler function

Some event handlers may only be used to fire side-effects with exec, and should stay in the current state.

useMachine({
  state1: {
     event1: ({exec}) => {
       exec(() => console.log("event with no return value"))
     }
  }
})

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.