Skip to content

Commit f970c65

Browse files
feat(aurelia): add preliminary enhance api
This is based on the new view engine’s enhance api. This api probably won’t change though the view engine’s api which is used by it may.
1 parent f7e93af commit f970c65

11 files changed

+304
-95
lines changed

dist/amd/aurelia-framework.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,20 @@ declare module 'aurelia-framework' {
101101
*/
102102
start(): Promise<Aurelia>;
103103

104+
/**
105+
* Enhances the host's existing elements with behaviors and bindings.
106+
*
107+
* @method enhance
108+
* @param {Object} bindingContext A binding context for the enhanced elements.
109+
* @param {string|Object} applicationHost The DOM object that Aurelia will attach to.
110+
* @return {Promise<Aurelia>} Returns the current Aurelia instance.
111+
*/
112+
enhance(bindingContext?: Object, applicationHost?: any): Promise<Aurelia>;
113+
104114
/**
105115
* Instantiates the root view-model and view and add them to the DOM.
106116
*
107-
* @method withSingleton
117+
* @method setRoot
108118
* @param {Object} root The root view-model to load upon bootstrap.
109119
* @param {string|Object} applicationHost The DOM object that Aurelia will attach to.
110120
* @return {Promise<Aurelia>} Returns the current Aurelia instance.

dist/amd/aurelia-framework.js

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -219,25 +219,33 @@ define(['exports', 'core-js', 'aurelia-logging', 'aurelia-metadata', 'aurelia-de
219219
});
220220
};
221221

222-
Aurelia.prototype.setRoot = function setRoot() {
222+
Aurelia.prototype.enhance = function enhance() {
223223
var _this3 = this;
224224

225+
var bindingContext = arguments[0] === undefined ? {} : arguments[0];
226+
var applicationHost = arguments[1] === undefined ? null : arguments[1];
227+
228+
this._configureHost(applicationHost);
229+
230+
return new Promise(function (resolve) {
231+
var viewEngine = _this3.container.get(_aureliaTemplating.ViewEngine);
232+
_this3.root = viewEngine.enhance(_this3.container, _this3.host, _this3.resources, bindingContext);
233+
_this3.root.attached();
234+
_this3._onAureliaComposed();
235+
return _this3;
236+
});
237+
};
238+
239+
Aurelia.prototype.setRoot = function setRoot() {
240+
var _this4 = this;
241+
225242
var root = arguments[0] === undefined ? 'app' : arguments[0];
226243
var applicationHost = arguments[1] === undefined ? null : arguments[1];
227244

228245
var compositionEngine,
229246
instruction = {};
230247

231-
applicationHost = applicationHost || this.host;
232-
233-
if (!applicationHost || typeof applicationHost == 'string') {
234-
this.host = document.getElementById(applicationHost || 'applicationHost') || document.body;
235-
} else {
236-
this.host = applicationHost;
237-
}
238-
239-
this.host.aurelia = this;
240-
this.container.registerInstance(_aureliaTemplating.DOMBoundary, this.host);
248+
this._configureHost(applicationHost);
241249

242250
compositionEngine = this.container.get(_aureliaTemplating.CompositionEngine);
243251
instruction.viewModel = root;
@@ -247,16 +255,33 @@ define(['exports', 'core-js', 'aurelia-logging', 'aurelia-metadata', 'aurelia-de
247255
instruction.host = this.host;
248256

249257
return compositionEngine.compose(instruction).then(function (root) {
250-
_this3.root = root;
258+
_this4.root = root;
251259
instruction.viewSlot.attached();
252-
var evt = new window.CustomEvent('aurelia-composed', { bubbles: true, cancelable: true });
253-
setTimeout(function () {
254-
return document.dispatchEvent(evt);
255-
}, 1);
256-
return _this3;
260+
_this4._onAureliaComposed();
261+
return _this4;
257262
});
258263
};
259264

265+
Aurelia.prototype._configureHost = function _configureHost(applicationHost) {
266+
applicationHost = applicationHost || this.host;
267+
268+
if (!applicationHost || typeof applicationHost == 'string') {
269+
this.host = document.getElementById(applicationHost || 'applicationHost') || document.body;
270+
} else {
271+
this.host = applicationHost;
272+
}
273+
274+
this.host.aurelia = this;
275+
this.container.registerInstance(_aureliaTemplating.DOMBoundary, this.host);
276+
};
277+
278+
Aurelia.prototype._onAureliaComposed = function _onAureliaComposed() {
279+
var evt = new window.CustomEvent('aurelia-composed', { bubbles: true, cancelable: true });
280+
setTimeout(function () {
281+
return document.dispatchEvent(evt);
282+
}, 1);
283+
};
284+
260285
return Aurelia;
261286
})();
262287

dist/aurelia-framework.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,20 @@ declare module 'aurelia-framework' {
101101
*/
102102
start(): Promise<Aurelia>;
103103

104+
/**
105+
* Enhances the host's existing elements with behaviors and bindings.
106+
*
107+
* @method enhance
108+
* @param {Object} bindingContext A binding context for the enhanced elements.
109+
* @param {string|Object} applicationHost The DOM object that Aurelia will attach to.
110+
* @return {Promise<Aurelia>} Returns the current Aurelia instance.
111+
*/
112+
enhance(bindingContext?: Object, applicationHost?: any): Promise<Aurelia>;
113+
104114
/**
105115
* Instantiates the root view-model and view and add them to the DOM.
106116
*
107-
* @method withSingleton
117+
* @method setRoot
108118
* @param {Object} root The root view-model to load upon bootstrap.
109119
* @param {string|Object} applicationHost The DOM object that Aurelia will attach to.
110120
* @return {Promise<Aurelia>} Returns the current Aurelia instance.

dist/aurelia-framework.js

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -271,27 +271,38 @@ export class Aurelia {
271271
});
272272
}
273273

274+
/**
275+
* Enhances the host's existing elements with behaviors and bindings.
276+
*
277+
* @method enhance
278+
* @param {Object} bindingContext A binding context for the enhanced elements.
279+
* @param {string|Object} applicationHost The DOM object that Aurelia will attach to.
280+
* @return {Promise<Aurelia>} Returns the current Aurelia instance.
281+
*/
282+
enhance(bindingContext:Object={}, applicationHost=null):Promise<Aurelia>{
283+
this._configureHost(applicationHost);
284+
285+
return new Promise((resolve) => {
286+
let viewEngine = this.container.get(ViewEngine);
287+
this.root = viewEngine.enhance(this.container, this.host, this.resources, bindingContext);
288+
this.root.attached();
289+
this._onAureliaComposed();
290+
return this;
291+
});
292+
}
293+
274294
/**
275295
* Instantiates the root view-model and view and add them to the DOM.
276296
*
277-
* @method withSingleton
297+
* @method setRoot
278298
* @param {Object} root The root view-model to load upon bootstrap.
279299
* @param {string|Object} applicationHost The DOM object that Aurelia will attach to.
280300
* @return {Promise<Aurelia>} Returns the current Aurelia instance.
281301
*/
282302
setRoot(root:string='app', applicationHost=null):Promise<Aurelia>{
283303
var compositionEngine, instruction = {};
284304

285-
applicationHost = applicationHost || this.host;
286-
287-
if (!applicationHost || typeof applicationHost == 'string') {
288-
this.host = document.getElementById(applicationHost || 'applicationHost') || document.body;
289-
} else {
290-
this.host = applicationHost;
291-
}
292-
293-
this.host.aurelia = this;
294-
this.container.registerInstance(DOMBoundary, this.host);
305+
this._configureHost(applicationHost);
295306

296307
compositionEngine = this.container.get(CompositionEngine);
297308
instruction.viewModel = root;
@@ -303,11 +314,28 @@ export class Aurelia {
303314
return compositionEngine.compose(instruction).then(root => {
304315
this.root = root;
305316
instruction.viewSlot.attached();
306-
var evt = new window.CustomEvent('aurelia-composed', { bubbles: true, cancelable: true });
307-
setTimeout(() => document.dispatchEvent(evt), 1);
317+
this._onAureliaComposed();
308318
return this;
309319
});
310320
}
321+
322+
_configureHost(applicationHost){
323+
applicationHost = applicationHost || this.host;
324+
325+
if (!applicationHost || typeof applicationHost == 'string') {
326+
this.host = document.getElementById(applicationHost || 'applicationHost') || document.body;
327+
} else {
328+
this.host = applicationHost;
329+
}
330+
331+
this.host.aurelia = this;
332+
this.container.registerInstance(DOMBoundary, this.host);
333+
}
334+
335+
_onAureliaComposed(){
336+
var evt = new window.CustomEvent('aurelia-composed', { bubbles: true, cancelable: true });
337+
setTimeout(() => document.dispatchEvent(evt), 1);
338+
}
311339
}
312340

313341
/**

dist/commonjs/aurelia-framework.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,20 @@ declare module 'aurelia-framework' {
101101
*/
102102
start(): Promise<Aurelia>;
103103

104+
/**
105+
* Enhances the host's existing elements with behaviors and bindings.
106+
*
107+
* @method enhance
108+
* @param {Object} bindingContext A binding context for the enhanced elements.
109+
* @param {string|Object} applicationHost The DOM object that Aurelia will attach to.
110+
* @return {Promise<Aurelia>} Returns the current Aurelia instance.
111+
*/
112+
enhance(bindingContext?: Object, applicationHost?: any): Promise<Aurelia>;
113+
104114
/**
105115
* Instantiates the root view-model and view and add them to the DOM.
106116
*
107-
* @method withSingleton
117+
* @method setRoot
108118
* @param {Object} root The root view-model to load upon bootstrap.
109119
* @param {string|Object} applicationHost The DOM object that Aurelia will attach to.
110120
* @return {Promise<Aurelia>} Returns the current Aurelia instance.

dist/commonjs/aurelia-framework.js

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -234,25 +234,33 @@ var Aurelia = (function () {
234234
});
235235
};
236236

237-
Aurelia.prototype.setRoot = function setRoot() {
237+
Aurelia.prototype.enhance = function enhance() {
238238
var _this3 = this;
239239

240+
var bindingContext = arguments[0] === undefined ? {} : arguments[0];
241+
var applicationHost = arguments[1] === undefined ? null : arguments[1];
242+
243+
this._configureHost(applicationHost);
244+
245+
return new Promise(function (resolve) {
246+
var viewEngine = _this3.container.get(_aureliaTemplating.ViewEngine);
247+
_this3.root = viewEngine.enhance(_this3.container, _this3.host, _this3.resources, bindingContext);
248+
_this3.root.attached();
249+
_this3._onAureliaComposed();
250+
return _this3;
251+
});
252+
};
253+
254+
Aurelia.prototype.setRoot = function setRoot() {
255+
var _this4 = this;
256+
240257
var root = arguments[0] === undefined ? 'app' : arguments[0];
241258
var applicationHost = arguments[1] === undefined ? null : arguments[1];
242259

243260
var compositionEngine,
244261
instruction = {};
245262

246-
applicationHost = applicationHost || this.host;
247-
248-
if (!applicationHost || typeof applicationHost == 'string') {
249-
this.host = document.getElementById(applicationHost || 'applicationHost') || document.body;
250-
} else {
251-
this.host = applicationHost;
252-
}
253-
254-
this.host.aurelia = this;
255-
this.container.registerInstance(_aureliaTemplating.DOMBoundary, this.host);
263+
this._configureHost(applicationHost);
256264

257265
compositionEngine = this.container.get(_aureliaTemplating.CompositionEngine);
258266
instruction.viewModel = root;
@@ -262,16 +270,33 @@ var Aurelia = (function () {
262270
instruction.host = this.host;
263271

264272
return compositionEngine.compose(instruction).then(function (root) {
265-
_this3.root = root;
273+
_this4.root = root;
266274
instruction.viewSlot.attached();
267-
var evt = new window.CustomEvent('aurelia-composed', { bubbles: true, cancelable: true });
268-
setTimeout(function () {
269-
return document.dispatchEvent(evt);
270-
}, 1);
271-
return _this3;
275+
_this4._onAureliaComposed();
276+
return _this4;
272277
});
273278
};
274279

280+
Aurelia.prototype._configureHost = function _configureHost(applicationHost) {
281+
applicationHost = applicationHost || this.host;
282+
283+
if (!applicationHost || typeof applicationHost == 'string') {
284+
this.host = document.getElementById(applicationHost || 'applicationHost') || document.body;
285+
} else {
286+
this.host = applicationHost;
287+
}
288+
289+
this.host.aurelia = this;
290+
this.container.registerInstance(_aureliaTemplating.DOMBoundary, this.host);
291+
};
292+
293+
Aurelia.prototype._onAureliaComposed = function _onAureliaComposed() {
294+
var evt = new window.CustomEvent('aurelia-composed', { bubbles: true, cancelable: true });
295+
setTimeout(function () {
296+
return document.dispatchEvent(evt);
297+
}, 1);
298+
};
299+
275300
return Aurelia;
276301
})();
277302

dist/es6/aurelia-framework.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,20 @@ declare module 'aurelia-framework' {
101101
*/
102102
start(): Promise<Aurelia>;
103103

104+
/**
105+
* Enhances the host's existing elements with behaviors and bindings.
106+
*
107+
* @method enhance
108+
* @param {Object} bindingContext A binding context for the enhanced elements.
109+
* @param {string|Object} applicationHost The DOM object that Aurelia will attach to.
110+
* @return {Promise<Aurelia>} Returns the current Aurelia instance.
111+
*/
112+
enhance(bindingContext?: Object, applicationHost?: any): Promise<Aurelia>;
113+
104114
/**
105115
* Instantiates the root view-model and view and add them to the DOM.
106116
*
107-
* @method withSingleton
117+
* @method setRoot
108118
* @param {Object} root The root view-model to load upon bootstrap.
109119
* @param {string|Object} applicationHost The DOM object that Aurelia will attach to.
110120
* @return {Promise<Aurelia>} Returns the current Aurelia instance.

0 commit comments

Comments
 (0)