Skip to content

Commit

Permalink
chore(view): make the created callback meaningful by supplying the vi…
Browse files Browse the repository at this point in the history
…ew instance

This is a BREAKING CHANGE. In the event that someone was actually using
the created callback…and in the event that they actually were relying
on the unstable execution context provided there, that has been
changed. Now the view instance is provided.
  • Loading branch information
EisenbergEffect committed Aug 13, 2015
1 parent 961604a commit 94d6bc0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/html-behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ export class HtmlBehaviorResource {
}
}

instruction.suppressBind = true;
return node;
}

Expand Down Expand Up @@ -321,6 +320,10 @@ export class HtmlBehaviorResource {
}
}

if(instruction.initiatedByBehavior && viewFactory){
behaviorInstance.view.created();
}

return behaviorInstance;
}

Expand Down
10 changes: 6 additions & 4 deletions src/instructions.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,41 @@ interface ViewCreateInstruction {
systemControlled?:boolean;
enhance?:boolean;
partReplacements?:Object;
initiatedByBehavior?:boolean;
}

export class BehaviorInstruction {
static normal = new BehaviorInstruction();
static contentSelector = new BehaviorInstruction(true);

static element(node:Node, type:HtmlBehaviorResource):BehaviorInstruction{
let instruction = new BehaviorInstruction();
let instruction = new BehaviorInstruction(true);
instruction.type = type;
instruction.attributes = {};
instruction.anchorIsContainer = !(node.hasAttribute('containerless') || type.containerless);
instruction.initiatedByBehavior = true;
return instruction;
}

static attribute(attrName:string, type?:HtmlBehaviorResource):BehaviorInstruction{
let instruction = new BehaviorInstruction();
let instruction = new BehaviorInstruction(true);
instruction.attrName = attrName;
instruction.type = type || null;
instruction.attributes = {};
return instruction;
}

static dynamic(host, executionContext, viewFactory){
let instruction = new BehaviorInstruction();
let instruction = new BehaviorInstruction(true);
instruction.host = host;
instruction.executionContext = executionContext;
instruction.viewFactory = viewFactory;
instruction.suppressBind = true;
return instruction;
}

constructor(suppressBind?:boolean=false){
this.suppressBind = suppressBind;
this.initiatedByBehavior = false;
this.systemControlled = false;
this.enhance = false;
this.partReplacements = null;
Expand Down
7 changes: 6 additions & 1 deletion src/view-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,13 @@ export class ViewFactory{
}

view = new View(container, fragment, behaviors, bindings, children, createInstruction.systemControlled, contentSelectors);
view.created(executionContext);

//if iniated by an element behavior, let the behavior trigger this callback once it's done creating the element
if(!createInstruction.initiatedByBehavior){
view.created();
}

//if the view creation is part of a larger creation, wait to bind until the root view initiates binding
if(!createInstruction.suppressBind){
view.bind(executionContext);
}
Expand Down
4 changes: 2 additions & 2 deletions src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export class View {
this.isAttached = false;
}

created(executionContext){
created(){
var i, ii, behaviors = this.behaviors;
for(i = 0, ii = behaviors.length; i < ii; ++i){
behaviors[i].created(executionContext);
behaviors[i].created(this);
}
}

Expand Down

0 comments on commit 94d6bc0

Please sign in to comment.