Giter VIP home page Giter VIP logo

backbone.statemachine's People

Contributors

afeld avatar antonyhell avatar cgarvis avatar donaldr avatar fab1en avatar sebpiq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

backbone.statemachine's Issues

Better support for initial state

For the moment, nothing is done automatically when starting your state machine with an initial state. This causes a pb for example with StatefulView, because the initial css class is not set.

StatefulModel

With intermediary states like "destroying", "saving", and so on ...

Refactor transition lookup

Now transition lookup is quite dumb : receive an event, lookup in the transitions hash, current state -> event ? Wildcard -> event ? get the data and starts the transition.

It would be cool to :
- "compile" the transitions
- be able to declare states not only as wildcard but, as a regex

Change callback names

enterCb and leaveCb to before and after respectfully. This feels more intuitive and looks cleaner.

Error on initial toState with StatefulView

When I try to enter the initial state
this.toState('placing')
This line:
this.stateClassName = (this._states[name].className || name);
throws the error
Uncaught TypeError: Cannot read property 'placing' of undefined

What gives? Looks like _states is not being initialized. I'm trying to define the state callbacks by setting the "states" hash on the object, but that doesn't seem to make a difference in terms of the error being thrown.

Enumerating states

Thinking on using this to wrap a Router (#16), I'm considering how dynamic routes would work. For example, are /posts/1 and /posts/2 different states? You don't know all the possible states (in this case, all available the post IDs) up front, and even if you did, you wouldn't want to enumerate them. How would a transition between posts be defined?

This question applies to the StateMachine in general but becomes really apparent when dealing with routes.

Calling startStateMachine() twice make events happen twice

If startStateMachine() is erroneously called twice, "all" events of the element are bound twice so every event triggered run the onMachineEvent callback twice.

It is very easy to make this mistake when you use the StatefulView version : you do not have to call startStateMachine() yourself in this case because it already has been called.

You should either make it safe to execute this code twice (by checking if it has already be initialized), or make it clear in the docs that startStateMachine() should not be called when using the StatefulView.

Provide a mixin for StatefulView

The fact that StatefulView is a ready-to-use backbone view, makes it harder to use it with some libraries that also do the same. Providing StatefulView as a mixin (like StateMachine) would solve that.

Make declaring states optional

Right now it is mandatory to declare state event if empty, but that doesn't really make sense. States can be also fetched and created automatically from the transitions object.

Add to cdnjs.com

Hi,

I'm considering using this on a project of mine and the way I'm coding my app, I'm handling pretty much all vendor scripts through a CDN. It'd be nice to see this one on there as well!

https://github.com/cdnjs/cdnjs

States declaration hash should accept anonymous functions

Callbacks are defined by function names (string) :

states: {
    visible: {enter: ['doShow'], leave: ['doHide']},
},
doShow: function() { this.el.show(); },
doHide: function() { this.el.hide(); }

Sometimes, when the callbacks are short, it's easier to use anonymous functions :

states: {
    visible: {
        enter: [function() { this.el.show(); }], 
        leave: [function() { this.el.hide(); }]
    },
}

This should be easy, but your _collectMethods prevent the use of anonymous functions. You can define anonymous function as callbacks in Vanilla Backbone events hash.

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.