Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples please #22

Open
michel-reyes opened this issue Sep 28, 2018 · 6 comments
Open

Examples please #22

michel-reyes opened this issue Sep 28, 2018 · 6 comments

Comments

@michel-reyes
Copy link

I read the article, the git documentation...but I don't know how to implement the state machine (stent( in my project. Any basic project example (more explanatory than the TODO example?)
_

@michel-reyes
Copy link
Author

For exmaple. Hot to use stent with UI events?

@krasimir
Copy link
Owner

Hey, there's an example with React here https://github.com/krasimir/stent/blob/master/docs/examples.md#integration-with-react If you need a more complex example can you please come with a use case. I'll be happy to setup one.

@michel-reyes
Copy link
Author

For example I'm working with another library from you "Navigo" :) and I want to move between pages using stent, my problem are the links. Right know it took my 3 steps (states) to get to a page (D), but from that page I want a link to the first one (A), how could I make to go from D to A in only one step?

const machine = stent.Machine.create('app', {
  state: { name: 'login' },
  transitions: {
    login: {
      sign: 'signing',
      enroll: 'enrolling',
      changePassword: 'changingPassword',
    },
    signing: {
      signing: 'signLoading',
    },
    signLoading: {
      fail: 'login',
      success: 'sendTo',
      unknowDevice: 'registerDevice',
    },
    registerDevice: {
      register: 'checkingDevice',
    },
    checkingDevice: {
      fail: 'registerDevice',
      success: 'login',
    },
  },
});

I want to go from registerDevice to Login

@krasimir
Copy link
Owner

krasimir commented Oct 2, 2018

I'm glad that you are using Navigo as well. I miss some context to answer properly here tho. What you control with Stent, is it pages or it is states of your app. It looks like you are mixing two different responsibilities.

@michel-reyes
Copy link
Author

Exactly I'm a little confuse in how to use stent and I'm mixing things. I'm not sure in how implement stent to control the stet of my app. I would like to do 2 things:

  1. control if a user can make an action in my app
  2. control if a user can go to an specific URI
    I'm using Vanilla JS with no framework.
    Thk for your time krasimir

@krasimir
Copy link
Owner

krasimir commented Oct 2, 2018

Well, I'll suggest to define what does state means to your app. This could be for example:

  • If the user is logged in or not
  • If the logging is in progress or not
  • Is the device working or not

Then put those states in a state machine. The second thing is: do you want to send the user to a different page based on the app state. If yes then I'll suggest to create a middle man and put the required logic there. For example, if you want to forward the user to a login page if he/she is not logged in you do something like:

if (isTheUserLoggedIn() === false) {
  router.navigate('login);
  machine.login();
}

So, my point is that the routing and the state management should be separated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants