Skip to content

Commit

Permalink
feat(View): default set action, optional element in constructor (defa…
Browse files Browse the repository at this point in the history
…ults to env.body)
  • Loading branch information
karfcz committed Jul 21, 2016
1 parent 2afdada commit 512e387
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ function mixin(obj, properties)
return obj;
}

function actionSet(event)
{
event.cursor.set(event.value);
return {
type: 'refreshFromRoot'
};
}

var View = createClass(
{
statics: {
Expand Down Expand Up @@ -286,12 +294,6 @@ var View = createClass(
}
else this.domEvents = [];

if(options.element)
{
this.element = options.element
options.element = null;
}

if(options.dispatcher)
{
this.dispatcher = options.dispatcher;
Expand All @@ -300,7 +302,15 @@ var View = createClass(

if(options.actions)
{
this.actions = options.actions;
this.actions = mixin({
set: actionSet
}, options.actions);
}
else if(this.parentView || this._isolated)
{
this.actions = {
set: actionSet
};
}
else this.actions = null;

Expand All @@ -310,6 +320,13 @@ var View = createClass(
}
else this.env = { document: document, window: window };

if(options.element)
{
this.element = options.element
options.element = null;
}
else this.element = this.env.document.body;

this.options = options;
},

Expand Down

0 comments on commit 512e387

Please sign in to comment.