sebpiq/backbone.statemachine

StatefulModel

Closed this issue · 5 comments

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

I second having a StatefulModel class.

Never really had the need for that myself ... so any idea what functionalities it should offer that vanilla StateMachine doesn't already have?

It would mostly be syntactic sugar so that I don't have to manually mixin the state machine on a Backbone model object. There isn't much utility other than that.

I just cribbed the shell of Backbone.StatefulView and do this:

Backbone.StatefulModel = (function(Backbone, _) {

  var StatefulModel = function(options) {
    this.startStateMachine(options);
    Backbone.Model.prototype.constructor.apply(this, arguments);
  }

  _.extend(StatefulModel.prototype, Backbone.Model.prototype, Backbone.StateMachine);

  StatefulModel.extend = Backbone.Model.extend;

  return StatefulModel;

}(Backbone, _));

Ok ... I'll add that now. If by using it you find that there should be some extra functionality, please suggest it here!

Ok done 3c74c63