Skip to content

Commit

Permalink
to be continued. Надо додумать реализацию параллельных состояний
Browse files Browse the repository at this point in the history
  • Loading branch information
holywarez committed Oct 4, 2009
1 parent 1cc40bc commit 66e3ea8
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 7 deletions.
34 changes: 34 additions & 0 deletions public/javascripts/lib/inplace/components.js
@@ -0,0 +1,34 @@
$inplace.components = {};

(function($){
$inplace.components.StandardSaveBehaviour = $inplace.states.Behaviour.clone()
.hasState('passive')
.hasTransition({event: 'save', target: 'saving', handlers: ['__trySaveChanges', 'onSave']})
.parentState()
.hasState('saving')
.hasTransition({event: 'save-successful', target: 'passive', handlers: ['__commitChanges', 'onSaveSuccess']})
.hasTransition({event: 'save-failed', target: 'passive', handlers: ['__rollbackChanges', 'onSaveFail']})
.parentState()
.setDefaultState('passive')
.reset()

.__trySaveChanges(function() {
this.sendParentMessage('save-changes');
});

$inplace.components.BaseBehaviour = $inplace.states.Behaviour.clone()
.hasState('inactive')
.hasTransition({ event: 'switch-on', target: 'active', handlers: ['__initializeComponent', 'onActivateComponent'] })
.parentState()
.hasState('active')
.hasTransition({ event: 'switch-off', target: 'inactive', handlers: 'onDeactivateComponent' })
.parentState()
.setDefaultState('inactive')
.reset();

$inplace.Component = $inplace.CompositeState.clone()
.addState($inplace.components.BaseBehaviour)
.addState($inplace.components.StandardSaveBehaviour);


})(jQuery);
14 changes: 10 additions & 4 deletions public/javascripts/lib/inplace/nodes.js
Expand Up @@ -64,13 +64,18 @@
}
},

sendMessage: function(msg) {
this._processMessage(msg);
sendMessage: function(topic, data, sender) {
var data = data || null;
var sender = sender || this;
this._processMessage(new $inplace.Message(topic, sender, data));
},

sendParentMessage: function(msg){
sendParentMessage: function(topic, data, sender){
var data = data || null;
var sender = sender || this;

if(!this.parentNode) return this;
this.parentNode._processChildMessage(msg);
this.parentNode._processChildMessage(new $inplace.Message(topic, sender, data);
return this;
},

Expand All @@ -89,6 +94,7 @@
//console.log('Enter to processMessage');
try {
this.messageHandler(msg);

if(this.__childs) {
this.__childs.forEach(function(child) {
child._processMessage(msg);
Expand Down
14 changes: 13 additions & 1 deletion public/javascripts/lib/inplace/states.js
Expand Up @@ -6,7 +6,17 @@
this.handlers = handlers;
};

$inplace.states.Behaviour = $inplace.State.clone();

$inplace.states.StateFinalizationException = { type: 'state-finalization-invalid' };

$inplace.CompositeState = $inplace.Node.clone()
.extend({
addState: function(state) {
this.appendChild(state.clone());
return this;
}
});

$inplace.State = $inplace.Node.clone()
.extend({
Expand Down Expand Up @@ -125,7 +135,9 @@
if('function' == typeof(object)) {
_this.__handlers[handlerName] = object;
} else {
_this.__handlers[handlerName].apply(_this, [object]);
if('function' == typeof(_this.handlers[handlerName])) {
_this.__handlers[handlerName].apply(_this, [object]);
}
}
return _this;
};
Expand Down
5 changes: 3 additions & 2 deletions public/test-js.html
Expand Up @@ -13,8 +13,9 @@
<script type="text/javascript" src="/javascripts/lib/inplace/utils.js"></script>
<script type="text/javascript" src="/javascripts/lib/inplace/meta.js"></script>
<script type="text/javascript" src="/javascripts/lib/inplace/nodes.js"></script>
<script type="text/javascript" src="/javascripts/lib/inplace/states.js"></script>
<script type="text/javascript" src="/javascripts/lib/inplace/test/states-test.js"></script>
<script type="text/javascript" src="/javascripts/lib/inplace/states.js"></script>
<script type="text/javascript" src="/javascripts/lib/inplace/components.js"></script>
<script type="text/javascript" src="/javascripts/lib/inplace/test/states-test.js"></script>

</head>

Expand Down

0 comments on commit 66e3ea8

Please sign in to comment.