Skip to content

Commit

Permalink
Merge pull request #1379 from BladeRunnerJS/initialize-knockout-plugi…
Browse files Browse the repository at this point in the history
…ns-after-attaching

Initialize knockout plug-ins after template added to page
  • Loading branch information
thanhc committed May 27, 2015
2 parents 2d49794 + b748c91 commit 16f9f2e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ function KnockoutComponent(sTemplateId, vPresentationModel) {
this.m_sTemplateId = sTemplateId;
this.m_eTemplate = this._getTemplate(sTemplateId);
this.m_oPresentationModel = vPresentationModel;
this.m_bViewBound = false;
this.m_bViewAttached = false;
}
br.implement( KnockoutComponent, Component );

Expand All @@ -47,15 +45,14 @@ br.extend(KnockoutComponent.TemplateNotFoundError, Errors.CustomError);
KnockoutComponent.prototype.setDisplayFrame = function(frame) {
this.m_oFrame = frame;

frame.on('attach', function() {
ko.applyBindings(this.m_oPresentationModel, this.m_eTemplate);
}.bind(this));

frame.setContent(this.getElement());
};

KnockoutComponent.prototype.getElement = function() {
if (!this.m_bViewBound) {
this.m_bViewBound = true;
ko.applyBindings(this.m_oPresentationModel, this.m_eTemplate);
}

return this.m_eTemplate;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ function PresenterComponent(sTemplateId, vPresentationModel) {
this.m_eTemplate = this._getTemplate(sTemplateId);
this.m_sPresentationModel = null;
this.m_oPresentationModel = null;
this.m_bViewBound = false;
this.m_bViewAttached = false;
this.m_oFrame = null;
this.m_pLifecycleListeners = [];
Expand Down Expand Up @@ -118,16 +117,14 @@ PresenterComponent.prototype.setDisplayFrame = function(frame) {
frame.on(event, getEventHandler.call(this, event), this);
}, this);

frame.setContent(this.getElement());
frame.on('attach', function() {
presenter_knockout.applyBindings(this.m_oPresentationModel, this.m_eTemplate);
}.bind(this));

frame.setContent(this.getElement());
};

PresenterComponent.prototype.getElement = function() {
if (!this.m_bViewBound) {
this.m_bViewBound = true;
presenter_knockout.applyBindings(this.m_oPresentationModel, this.m_eTemplate);
}

return this.m_eTemplate;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Workbench.prototype.displayComponent = function(oComponent, width, height)

this.center(simpleFrame.getElement());
document.body.appendChild(simpleFrame.getElement());
simpleFrame.trigger('attach');
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ brjs.dashboard.app.DashboardApp = function(oDashboardService, oPageUrlService, o
this.m_oPresentationModel = new brjs.dashboard.app.model.DashboardPresentationModel(oDashboardService, oPageUrlService, oWindowOpenerService, oLocalStorage, oBrowserDetector);
this.m_oPresenterComponent = new br.presenter.component.PresenterComponent("brjs.dashboard.app.root", this.m_oPresentationModel);

// TODO: update dashboard to use new component interface.
// TODO: add proper frame support
eDisplayElement.appendChild(this.m_oPresenterComponent.getElement());

// this.m_oPresenterComponent.onOpen();
var frame = new br.component.SimpleFrame(this.m_oPresenterComponent, null, null);
eDisplayElement.appendChild(frame.getElement());
frame.trigger('attach');

this.m_bAppsLoaded = false;
oPageUrlService.addPageUrlListener(this._onPageUrlUpdated.bind(this), true);
Expand Down

0 comments on commit 16f9f2e

Please sign in to comment.