sebpiq / backbone.statemachine Goto Github PK
View Code? Open in Web Editor NEWSimple finite-state machine for Backbone. View states made easy. Synchronizing your application's parts with events made easy.
License: MIT License
Simple finite-state machine for Backbone. View states made easy. Synchronizing your application's parts with events made easy.
License: MIT License
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.
Hi i am very interested in your state machine.
I want to use it with a "view manager".
Unfortunatly i can't make the basic examples work...
doShow: function() { this.el.show(); } and doHide: function() { this.el.hide(); } are not called
http://lbineau.com/tests/statemachine/examples/example0.html
http://lbineau.com/tests/statemachine/examples/example1.html
Any idea ?
With intermediary states like "destroying", "saving", and so on ...
I've been reading about Ember's Router (and how it works in the context of an application) - any thoughts about how this might interact with the Backbone Router, or if a special subclass can be added?
test against 0.9
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
enterCb
and leaveCb
to before
and after
respectfully. This feels more intuitive and looks cleaner.
Write a more useful example for Backbone.Stateful views. e.g. a picture viewer.
Pipe events triggered by a state machine to another state machine.
The debugger should be in a separate JS file, to not clutter backbone.statemachine.js
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.
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.
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.
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.
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.
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!
Right now there is separation between state machine events and backbone events (e.g. triggering a state machine event with 'receive') ... there shouldn't be.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.