Skip to content

Commit

Permalink
feat(all): incorporate pal
Browse files Browse the repository at this point in the history
  • Loading branch information
EisenbergEffect committed Oct 10, 2015
1 parent ba385b9 commit 4bc7516
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 55 deletions.
5 changes: 5 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ System.config({
"aurelia-loader": "github:aurelia/loader@0.9.0",
"aurelia-logging": "github:aurelia/logging@0.7.0",
"aurelia-metadata": "github:aurelia/metadata@0.8.0",
"aurelia-pal": "github:aurelia/pal@0.1.10",
"aurelia-pal-browser": "github:aurelia/pal-browser@0.1.13",
"aurelia-path": "github:aurelia/path@0.9.0",
"aurelia-task-queue": "github:aurelia/task-queue@0.7.0",
"aurelia-templating": "github:aurelia/templating@0.15.0",
Expand All @@ -45,6 +47,9 @@ System.config({
"github:aurelia/metadata@0.8.0": {
"core-js": "npm:core-js@0.9.18"
},
"github:aurelia/pal-browser@0.1.13": {
"aurelia-pal": "github:aurelia/pal@0.1.10"
},
"github:aurelia/templating@0.15.0": {
"aurelia-binding": "github:aurelia/binding@0.9.0",
"aurelia-dependency-injection": "github:aurelia/dependency-injection@0.10.0",
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
"aurelia-loader": "github:aurelia/loader@^0.9.0",
"aurelia-logging": "github:aurelia/logging@^0.7.0",
"aurelia-metadata": "github:aurelia/metadata@^0.8.0",
"aurelia-pal": "github:aurelia/pal@^0.1.10",
"aurelia-path": "github:aurelia/path@^0.9.0",
"aurelia-task-queue": "github:aurelia/task-queue@^0.7.0",
"aurelia-templating": "github:aurelia/templating@^0.15.0",
"core-js": "npm:core-js@^0.9.5"
},
"devDependencies": {
"aurelia-pal-browser": "github:aurelia/pal-browser@^0.1.13",
"babel": "npm:babel-core@^5.1.13",
"babel-runtime": "npm:babel-runtime@^5.1.13",
"core-js": "npm:core-js@^0.9.5"
Expand Down
45 changes: 16 additions & 29 deletions src/aurelia.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*eslint no-unused-vars:0*/
import * as core from 'core-js';
import 'core-js';
import * as TheLogManager from 'aurelia-logging';
import {Container} from 'aurelia-dependency-injection';
import {Loader} from 'aurelia-loader';
Expand All @@ -10,29 +10,12 @@ import {
ViewSlot,
ViewResources,
CompositionEngine,
Animator,
DOMBoundary
Animator
} from 'aurelia-templating';

if (!window.CustomEvent || typeof window.CustomEvent !== 'function') {
let CustomEvent = function(event, params) {
params = params || {
bubbles: false,
cancelable: false,
detail: undefined
};

let evt = document.createEvent('CustomEvent');
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
return evt;
};

CustomEvent.prototype = window.Event.prototype;
window.CustomEvent = CustomEvent;
}
import {DOM} from 'aurelia-pal';

function preventActionlessFormSubmit() {
document.body.addEventListener('submit', evt => {
DOM.addEventListener('submit', evt => {
const target = evt.target;
const action = target.action;

Expand Down Expand Up @@ -84,19 +67,19 @@ export class Aurelia {
return this.use.apply().then(() => {
preventActionlessFormSubmit();

if (!this.container.hasHandler(BindingLanguage)) {
if (!this.container.hasResolver(BindingLanguage)) {
let message = 'You must configure Aurelia with a BindingLanguage implementation.';
this.logger.error(message);
throw new Error(message);
}

if (!this.container.hasHandler(Animator)) {
if (!this.container.hasResolver(Animator)) {
Animator.configureDefault(this.container);
}

this.logger.info('Aurelia Started');
let evt = new window.CustomEvent('aurelia-started', { bubbles: true, cancelable: true });
document.dispatchEvent(evt);
let evt = DOM.createCustomEvent('aurelia-started', { bubbles: true, cancelable: true });
DOM.dispatchEvent(evt);
return this;
});
}
Expand Down Expand Up @@ -153,20 +136,24 @@ export class Aurelia {
applicationHost = applicationHost || this.host;

if (!applicationHost || typeof applicationHost === 'string') {
this.host = document.getElementById(applicationHost || 'applicationHost') || document.body;
this.host = DOM.getElementById(applicationHost || 'applicationHost');
} else {
this.host = applicationHost;
}

if (!this.host) {
throw new Error('No applicationHost was specified.');
}

this.hostConfigured = true;
this.host.aurelia = this;
this.hostSlot = new ViewSlot(this.host, true);
this.hostSlot.transformChildNodesIntoView();
this.container.registerInstance(DOMBoundary, this.host);
this.container.registerInstance(DOM.boundary, this.host);
}

_onAureliaComposed() {
let evt = new window.CustomEvent('aurelia-composed', { bubbles: true, cancelable: true });
setTimeout(() => document.dispatchEvent(evt), 1);
let evt = DOM.createCustomEvent('aurelia-composed', { bubbles: true, cancelable: true });
setTimeout(() => DOM.dispatchEvent(evt), 1);
}
}
2 changes: 1 addition & 1 deletion src/framework-configuration.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*eslint no-unused-vars:0, no-cond-assign:0*/
import * as core from 'core-js';
import 'core-js';
import * as TheLogManager from 'aurelia-logging';
import {ViewEngine} from 'aurelia-templating';
import {join} from 'aurelia-path';
Expand Down
32 changes: 11 additions & 21 deletions test/aurelia.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import {Container} from 'aurelia-dependency-injection';
import {Loader} from 'aurelia-loader';
import {BindingLanguage, ViewSlot, ViewResources, CompositionEngine} from 'aurelia-templating';
import {FrameworkConfiguration} from '../src/framework-configuration';
import {initialize} from 'aurelia-pal-browser';

describe('aurelia', () => {
beforeAll(() => initialize());

describe("constructor", () => {

it("should have good defaults", () => {
Expand Down Expand Up @@ -53,8 +56,8 @@ describe('aurelia', () => {
resolve();
}));

mockContainer = jasmine.createSpyObj('container', ['registerInstance', 'hasHandler', 'get', 'makeGlobal']);
mockContainer.hasHandler.and.returnValue(true);
mockContainer = jasmine.createSpyObj('container', ['registerInstance', 'hasResolver', 'get', 'makeGlobal']);
mockContainer.hasResolver.and.returnValue(true);
mockContainer.get.and.returnValue(mockViewEngine);

mockPlugin = jasmine.createSpyObj('plugin', ['apply']);
Expand Down Expand Up @@ -86,10 +89,10 @@ describe('aurelia', () => {

//I'm going to assume start should fail in this case.
it("should check for a binding language and log an error if one is not set", (done) => {
mockContainer.hasHandler.and.returnValue(false);
mockContainer.hasResolver.and.returnValue(false);
aurelia.start()
.then(() => expect(true).toBeFalsy("Should have not started up"))
.catch(() => expect(mockContainer.hasHandler).toHaveBeenCalledWith(BindingLanguage))
.catch(() => expect(mockContainer.hasResolver).toHaveBeenCalledWith(BindingLanguage))
.then(done);
});

Expand Down Expand Up @@ -134,22 +137,8 @@ describe('aurelia', () => {
}
});

//This needs to be reworded
it("should default the host to the document body if the supplied applicationHost is a string and no element with that id is found", (done) => {
var documentSpy = spyOn(document, "getElementById").and.callThrough();
aurelia.setRoot(rootModel, "someIDThatShouldNotExist")
.then((result) => {
expect(result).toBe(aurelia);
expect(aurelia.host).toBe(document.body);
expect(document.body.aurelia).toBe(aurelia);
expect(documentSpy).toHaveBeenCalledWith("someIDThatShouldNotExist");
})
.catch((reason) => expect(false).toBeTruthy(reason))
.then(done);
});

it("should try and find the element with an id of applicationHost if one is not supplied", (done) => {
var documentSpy = spyOn(document, "getElementById").and.callThrough();
let documentSpy = spyOn(document, "getElementById").and.returnValue(document.body);
aurelia.setRoot(rootModel)
.then((result) => {
expect(result).toBe(aurelia);
Expand All @@ -164,7 +153,7 @@ describe('aurelia', () => {
it("should use the applicationHost if it's not a string as the host", (done) => {
//This wouldn't have succeeded because registerInstance checks the type
//But the function doesn't guard against applicationHost so this test is valid
var host = { firstChild:{} };
let host = { firstChild:{} };
aurelia.setRoot(rootModel, host)
.then((result) => {
expect(result).toBe(aurelia);
Expand All @@ -177,6 +166,7 @@ describe('aurelia', () => {

it("should call the compose function of the composition instance with a well formed instruction", (done) => {
let attachedSpy;
let documentSpy = spyOn(document, "getElementById").and.returnValue(document.body);
mockCompositionEngine.compose.and.callFake((instruction) => {
attachedSpy = spyOn(instruction.viewSlot, 'attached');
return composePromise;
Expand All @@ -199,7 +189,7 @@ describe('aurelia', () => {
});

it("should fire a custom aurelia-composed event when it's done", (done) => {

let documentSpy = spyOn(document, "getElementById").and.returnValue(document.body);
composeListener = (event) => {
expect(event).toEqual(jasmine.any(window.Event));
expect(event.type).toEqual("aurelia-composed");
Expand Down
13 changes: 9 additions & 4 deletions test/framework-configuration.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {FrameworkConfiguration} from '../src/framework-configuration';
import {Aurelia} from '../src/aurelia';
import {Metadata} from 'aurelia-metadata';
import {initialize} from 'aurelia-pal-browser';

describe('the framework config', () => {
beforeAll(() => initialize());

it('should initialize', () => {
let aureliaMock = jasmine.createSpyObj('aureliaMock', ['loader']);
let config = new FrameworkConfiguration(aureliaMock);
Expand Down Expand Up @@ -71,8 +74,8 @@ describe('the framework config', () => {
resolve();
}));

mockContainer = jasmine.createSpyObj('container', ['registerInstance', 'hasHandler', 'get', 'makeGlobal']);
mockContainer.hasHandler.and.returnValue(true);
mockContainer = jasmine.createSpyObj('container', ['registerInstance', 'hasResolver', 'get', 'makeGlobal']);
mockContainer.hasResolver.and.returnValue(true);
mockContainer.get.and.returnValue(mockViewEngine);

aurelia = new Aurelia(mockLoader, mockContainer, mockResources);
Expand All @@ -89,6 +92,7 @@ describe('the framework config', () => {
});
});

aurelia.loader.normalizeSync = jasmine.createSpy('normalizeSync').and.callFake(input => input);
aurelia.loader.loadModule = loadModule;
});

Expand Down Expand Up @@ -182,10 +186,11 @@ describe('the framework config', () => {
resolve();
}));

mockContainer = jasmine.createSpyObj('container', ['registerInstance', 'hasHandler', 'get', 'makeGlobal']);
mockContainer.hasHandler.and.returnValue(true);
mockContainer = jasmine.createSpyObj('container', ['registerInstance', 'hasResolver', 'get', 'makeGlobal']);
mockContainer.hasResolver.and.returnValue(true);
mockContainer.get.and.returnValue(mockViewEngine);

mockLoader.normalizeSync = jasmine.createSpy('normalizeSync').and.callFake(input => input);
aurelia = new Aurelia(mockLoader, mockContainer, mockResources);
});

Expand Down

0 comments on commit 4bc7516

Please sign in to comment.