Skip to content

v0.7.0

Compare
Choose a tag to compare
@LevelbossMike LevelbossMike released this 19 Apr 07:22
· 282 commits to master since this release

From this release on ember-statecharts will use xstate's interpreter-functionality internally. This brings several advantages over the prior approach of providing a custom interpreter. Most importantly we now support all features that xstate provides 🎉 - This means ember-statecharts now also supports new features like delays and activities.

!!Warning!!

This is a 💥 breaking release. To upgrade your projects you have to update your statechart configurations:

Parameter order for statechart actions has changed

To align with xstate we don't change the order of params passed to actions anymore.

This means:

// ....
statechart: statechart({
  // ....
}, {
  actions: {
    doSomething(data, context) {
      context.anInternalComponentAction();
    }
  }
});

needs to be changed to:

// ....
statechart: statechart({
  // ....
}, {
  actions: {
    doSomething(context, eventObject) {
      // see the rest of the relase notes for changes regarding the `data`-param
      context.anInternalComponentAction();
    }
  }
});

No this in actions anymore

statechart actions won't have their implementing object set as the this-context anymore.

This means actions like this:

// ....
statechart: statechart({
  // ....
}, {
  actions: {
    doSomething() {
      this.anInternalComponentAction();
    }
  }
});

will need to be changed to this:

// ....
statechart: statechart({
  // ....
}, {
  actions: {
    doSomething(context, /* eventObject */) {
      context.anInternalComponentAction();
    }
  }
});

No magic data wrapping of data passed to events

To align with xstate's behavior we won't wrap data passed to events into a magic data-property anymore - we will use xstate's eventObjects instead:

This means:

statechart: statechart({
   // ...
}, {
  actions: {
    sayName(context, data) {
      const { name } = data;
      // name: 'tomster'     
      // ...
    }
  }
  
}),

will need to be changed to:

statechart: statechart({
   // ...
}, {
  actions: {
    sayName(context, eventObject) {
       const { type, name } = eventObject;
       // name: 'tomster', type: 'sayHello'     
      // ...
    }
  }
  
}),

Summary

Overall this is a very exciting release that aligns ember-statecharts with xstate and makes it future-proof. We are very excited to finally support all of xstate's features and we feel this release cleans up ember-statecharts significantly.

We are sorry for the caused churn but we are certain the additional features make the effort of changing your statechart configurations worthwhile.

You can have a look at the changes we had to do to make ember-statecharts test-suite compatible with the interpreter changes in this release in the PR that added this enhancement.