Skip to content

Commit

Permalink
Allow Behavior#init to recive a custom parameter during behavior inst…
Browse files Browse the repository at this point in the history
…antiation
  • Loading branch information
roperzh committed Sep 12, 2014
1 parent 2eb004f commit f447517
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// ```

Essential.Behavior = Proto.extend({
constructor: function(domElement, lateStart) {
constructor: function(domElement, lateStart, initParams) {
this.el = domElement;

// A behavior can be initialized without attaching events with the `lateStart`
Expand All @@ -48,16 +48,16 @@ Essential.Behavior = Proto.extend({
// ```

if(!lateStart) {
this.start();
this.start(initParams);
}
},

start: function() {
start: function(initParams) {
this.delegateEvents();
this.listenChannels();

if(typeof this.init === "function") {
this.init();
this.init(initParams);
}
},

Expand Down
14 changes: 14 additions & 0 deletions test/behavior_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,18 @@ describe("Essential.Behavior", function() {
var behavior = Essential.Behavior.extend({});
expect(behavior.priority).to.be.eq(0);
});

it("mut allow a custom parameter on initialization", function() {
var firstFlag = true;
var secondFlag = false;
var BehaviorWithParam = Essential.Behavior.extend({
init: function(firstFlagAsParam) {
secondFlag = firstFlagAsParam;
}
});

BehaviorWithParam.new(document, false, firstFlag);

expect(secondFlag).to.be.equal(firstFlag);
});
});

0 comments on commit f447517

Please sign in to comment.