All Projects → LevelbossMike → ember-statecharts

LevelbossMike / ember-statecharts

Licence: MIT license
Statecharts for Ember.js applications

Programming Languages

javascript
184084 projects - #8 most used programming language
Handlebars
879 projects
typescript
32286 projects
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to ember-statecharts

use-router-machine
Router state-machine hook, powered by XState (DEPRECATED).
Stars: ✭ 11 (-83.58%)
Mutual labels:  statecharts, xstate
xstate-react-router
XState connector to React Router.
Stars: ✭ 23 (-65.67%)
Mutual labels:  statecharts, xstate
xstate.dart
xstate for dart & flutter
Stars: ✭ 31 (-53.73%)
Mutual labels:  statecharts, xstate
Useauth
The simplest way to add authentication to your React app. Supports various providers.
Stars: ✭ 2,532 (+3679.1%)
Mutual labels:  xstate
statemachine-go
🚦 Declarative Finite-State Machines in Go
Stars: ✭ 47 (-29.85%)
Mutual labels:  statecharts
ember-statechart-component
Statecharts as components. No classes. Pure declarative state transitions.
Stars: ✭ 28 (-58.21%)
Mutual labels:  xstate
pwl
Password Lense: reveal character types in a password
Stars: ✭ 20 (-70.15%)
Mutual labels:  xstate
eslint-plugin-xstate
ESLint plugin to check for common mistakes and enforce good practices when using XState.
Stars: ✭ 19 (-71.64%)
Mutual labels:  xstate
xsystem
Building Blocks for XState-based Actor Systems.
Stars: ✭ 40 (-40.3%)
Mutual labels:  xstate
podhouse
The best way to listen to your favorite podcasts.
Stars: ✭ 39 (-41.79%)
Mutual labels:  xstate
elderform
💪🏽 Form creation made easy, backed by state machines
Stars: ✭ 30 (-55.22%)
Mutual labels:  xstate
annihilate
js action game
Stars: ✭ 49 (-26.87%)
Mutual labels:  xstate
use-secret-code
Custom hook for adding cheat codes to your React app.
Stars: ✭ 16 (-76.12%)
Mutual labels:  xstate
storybook-xstate-addon
A storybook addon to assist with writing stories that rely on xstate
Stars: ✭ 48 (-28.36%)
Mutual labels:  xstate
Imove
Move your mouse, generate code from flow chart
Stars: ✭ 3,282 (+4798.51%)
Mutual labels:  xstate
xstate-angular
Examples and a small library for using XState in Angular
Stars: ✭ 27 (-59.7%)
Mutual labels:  xstate
Cypress Realworld App
A payment application to demonstrate real-world usage of Cypress testing methods, patterns, and workflows.
Stars: ✭ 2,888 (+4210.45%)
Mutual labels:  xstate
liblucy
Core Lucy compiler
Stars: ✭ 391 (+483.58%)
Mutual labels:  xstate
xstate
State machines and statecharts for the modern web.
Stars: ✭ 21,286 (+31670.15%)
Mutual labels:  statecharts
angular-xstate
Exemplary real world application built with Angular 8 and state machines
Stars: ✭ 45 (-32.84%)
Mutual labels:  xstate

ember-statecharts CI Ember Observer Score

This addon provides a statechart abstraction based on XState for adding statecharts to your Ember.js application. Statecharts can be used to describe complex behaviour of your objects and separate ui-concern from behavioral concerns in your applications. This is especially useful in Ember.Component-architecture but can be used across all layers of your application (e.g. when implementing global application state).

View the docs here.

Compatibility

  • Ember.js v3.24 or above
  • Ember CLI v3.20 or above
  • Node.js v12 or above

For classic Ember.js-versions pre Ember Octane please use the 0.8.x-version of this addon.

For Ember.js versions < 3.24 please use the 0.13.x-version of this addon.

Installation

ember install ember-statecharts

Because ember-statecharts works with XState internally you have to install it as a dependency as well.

yarn add --dev xstate

or

npm install --save-dev xstate

Usage

Statecharts have been around for a long time and have been used to model stateful, reactive system successfully. You can read about statecharts in the original paper Statecharts - A Visual Formalism for Complex Systems by David Harel.

With statecharts we finally have a good abstraction to model and discuss behaviour with other stakeholders of our applications in addition to a design language that visualizes this behaviour. Here's an example of a button component:

button

In addition to their modeling capabilities Statecharts are executable and can be used to drive user experience behavior in your Ember.js applications:

import Component from '@glimmer/component';
import { action } from '@ember/object';
import { task } from 'ember-concurrency';

import { matchesState, useMachine } from 'ember-statecharts';
import { Machine } from 'xstate';

function noop() {}

const buttonMachine = Machine(
  {
    initial: 'idle',
    states: {
      idle: {
        on: {
          SUBMIT: 'busy',
        },
      },
      busy: {
        entry: ['handleSubmit'],
        on: {
          SUCCESS: 'success',
          ERROR: 'error',
        },
      },
      success: {
        entry: ['handleSuccess'],
        on: {
          SUBMIT: 'busy',
        },
      },
      error: {
        entry: ['handleError'],
        on: {
          SUBMIT: 'busy',
        },
      },
    },
  },
  {
    actions: {
      handleSubmit() {},
      handleSuccess() {},
      handleError() {},
    },
  }
);

export default class QuickstartButton extends Component {
  get onClick() {
    return this.args.onClick || noop;
  }

  statechart = useMachine(this, () => {
    const { performSubmitTask, onSuccess, onError } = this;

    return {
      machine: quickstartButtonMachine.withConfig({
        actions: {
          handleSubmit: performSubmitTask,
          handleSuccess: onSuccess,
          handleError: onError,
        },
      }),
    };
  });

  @matchesState('busy')
  isBusy;

  get isDisabled() {
    return this.isBusy || this.args.disabled;
  }

  @task(function* () {
    try {
      const result = yield this.onClick();
      this.statechart.send('SUCCESS', { result });
    } catch (e) {
      this.statechart.send('ERROR', { error: e });
    }
  })
  handleSubmitTask;

  @action
  handleClick() {
    this.statechart.send('SUBMIT');
  }

  @action
  onSuccess(_context, { result }) {
    return (this.args.onSuccess && this.args.onSuccess(result)) || noop();
  }

  @action
  onError(_context, { error }) {
    return (this.args.onError && this.args.onError(error)) || noop();
  }

  @action
  performSubmitTask() {
    this.handleSubmitTask.perform();
  }
}

Please refer to the documentation page for a detailed guide of how you can use statecharts to improve your Ember.js application architecture.

Contributing

See the Contributing guide for details.

License

This project has been developed by https://www.effective-ember.com/ and contributors. It is licensed under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].