Skip to content

Commit

Permalink
chore(*): bumped to 2.0.2 - #20
Browse files Browse the repository at this point in the history
  • Loading branch information
ckotzbauer committed Oct 26, 2017
1 parent 9781f4d commit 61c0e2b
Show file tree
Hide file tree
Showing 27 changed files with 392 additions and 329 deletions.
5 changes: 3 additions & 2 deletions dist/amd/aurelia-knockout.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
define(["require", "exports", "./knockout-bindable", "./knockout-composition", "./knockout-custom-attribute", "./require-polyfill", "./knockout-custom-attribute", "./knockout-composition", "./require-polyfill"], function (require, exports, knockout_bindable_1, knockout_composition_1, knockout_custom_attribute_1, require_polyfill_1, knockout_custom_attribute_2, knockout_composition_2, require_polyfill_2) {
define(["require", "exports", "aurelia-pal", "./knockout-bindable", "./knockout-composition", "./knockout-custom-attribute", "./require-polyfill", "./knockout-custom-attribute", "./knockout-composition", "./require-polyfill"], function (require, exports, aurelia_pal_1, knockout_bindable_1, knockout_composition_1, knockout_custom_attribute_1, require_polyfill_1, knockout_custom_attribute_2, knockout_composition_2, require_polyfill_2) {
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(knockout_bindable_1);
__export(knockout_composition_1);
__export(knockout_custom_attribute_1);
__export(require_polyfill_1);
function configure(frameworkConfig) {
// register custom attribute
frameworkConfig.globalResources('./knockout-custom-attribute');
frameworkConfig.globalResources(aurelia_pal_1.PLATFORM.moduleName('./knockout-custom-attribute'));
// register knockout custom binding for composition logic
frameworkConfig.container.get(knockout_composition_2.KnockoutComposition).register();
// register require function in window object if not available
Expand Down
43 changes: 23 additions & 20 deletions dist/amd/knockout-bindable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
};
define(["require", "exports", "aurelia-binding", "aurelia-templating", "aurelia-dependency-injection", "knockout"], function (require, exports, aurelia_binding_1, aurelia_templating_1, aurelia_dependency_injection_1, ko) {
"use strict";
let KnockoutBindable = class KnockoutBindable {
constructor(observerLocator) {
Object.defineProperty(exports, "__esModule", { value: true });
var KnockoutBindable = (function () {
function KnockoutBindable(observerLocator) {
this.subscriptions = [];
this.observerLocator = observerLocator;
}
Expand All @@ -21,42 +22,44 @@ define(["require", "exports", "aurelia-binding", "aurelia-templating", "aurelia-
* @param target - the target view model
* @param applyOnlyObservables - `true` if only observable values should be applied, false by default.
*/
applyBindableValues(data, target, applyOnlyObservables) {
KnockoutBindable.prototype.applyBindableValues = function (data, target, applyOnlyObservables) {
var _this = this;
data = data || {};
target = target || {};
applyOnlyObservables = applyOnlyObservables === undefined ? true : applyOnlyObservables;
let keys = Object.keys(data);
keys.forEach((key) => {
let outerValue = data[key];
let isObservable = ko.isObservable(outerValue);
var keys = Object.keys(data);
keys.forEach(function (key) {
var outerValue = data[key];
var isObservable = ko.isObservable(outerValue);
if (isObservable || !applyOnlyObservables) {
let observer = this.getObserver(target, key);
if (observer && observer instanceof aurelia_templating_1.BehaviorPropertyObserver) {
observer.setValue(isObservable ? ko.unwrap(outerValue) : outerValue);
var observer_1 = _this.getObserver(target, key);
if (observer_1 && observer_1 instanceof aurelia_templating_1.BehaviorPropertyObserver) {
observer_1.setValue(isObservable ? ko.unwrap(outerValue) : outerValue);
}
if (isObservable) {
this.subscriptions.push(outerValue.subscribe((newValue) => {
observer.setValue(newValue);
_this.subscriptions.push(outerValue.subscribe(function (newValue) {
observer_1.setValue(newValue);
}));
}
}
});
let originalUnbind = target.unbind;
target.unbind = () => {
this.subscriptions.forEach((subscription) => {
var originalUnbind = target.unbind;
target.unbind = function () {
_this.subscriptions.forEach(function (subscription) {
subscription.dispose();
});
this.subscriptions = [];
_this.subscriptions = [];
if (originalUnbind) {
originalUnbind.call(target);
}
};
}
};
/** internal: do not use */
getObserver(target, key) {
KnockoutBindable.prototype.getObserver = function (target, key) {
return this.observerLocator.getObserver(target, key);
}
};
};
return KnockoutBindable;
}());
KnockoutBindable = __decorate([
aurelia_dependency_injection_1.inject(aurelia_binding_1.ObserverLocator)
], KnockoutBindable);
Expand Down
72 changes: 39 additions & 33 deletions dist/amd/knockout-composition.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,31 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
};
define(["require", "exports", "knockout", "aurelia-dependency-injection", "aurelia-loader", "aurelia-templating"], function (require, exports, ko, aurelia_dependency_injection_1, aurelia_loader_1, aurelia_templating_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function endsWith(s, suffix) {
return s.indexOf(suffix, s.length - suffix.length) !== -1;
}
function getMatchingProperty(result, propName) {
let properties = Object.keys(result);
for (let index = 0; index < properties.length; index++) {
let prop = properties[index].toLowerCase();
var properties = Object.keys(result);
for (var index = 0; index < properties.length; index++) {
var prop = properties[index].toLowerCase();
if (prop.indexOf(propName) !== -1) {
return properties[index];
}
}
return null;
}
function callEvent(element, eventName, args) {
let viewModel = ko.dataFor(element.children[0]);
let func = viewModel[eventName];
var viewModel = ko.dataFor(element.children[0]);
var func = viewModel[eventName];
if (func && typeof func === 'function') {
func.apply(viewModel, args);
}
}
function doComposition(element, unwrappedValue, viewModel) {
this.buildCompositionSettings(unwrappedValue, viewModel).then((settings) => {
composeElementInstruction.call(this, element, settings).then(() => {
var _this = this;
this.buildCompositionSettings(unwrappedValue, viewModel).then(function (settings) {
composeElementInstruction.call(_this, element, settings).then(function () {
callEvent(element, 'compositionComplete', [element, element.parentElement]);
});
});
Expand All @@ -38,54 +40,56 @@ define(["require", "exports", "knockout", "aurelia-dependency-injection", "aurel
return processInstruction.call(this, instruction);
}
function processInstruction(instruction) {
var _this = this;
instruction.container = instruction.container || this.container;
instruction.executionContext = instruction.executionContext || this;
instruction.viewSlot = instruction.viewSlot || this.viewSlot;
instruction.viewResources = instruction.viewResources || this.viewResources;
instruction.currentBehavior = instruction.currentBehavior || this.currentBehavior;
return this.compositionEngine.compose(instruction).then((next) => {
this.currentBehavior = next;
this.currentViewModel = next ? next.executionContext : null;
return this.compositionEngine.compose(instruction).then(function (next) {
_this.currentBehavior = next;
_this.currentViewModel = next ? next.executionContext : null;
});
}
function loadModule(moduleId, loader) {
return loader.loadModule(moduleId);
}
let KnockoutComposition = class KnockoutComposition {
constructor(compositionEngine, container, loader) {
var KnockoutComposition = (function () {
function KnockoutComposition(compositionEngine, container, loader) {
this.compositionEngine = compositionEngine;
this.container = container;
this.loader = loader;
}
/**
* Registers the `compose` Knockout Binding to use Compositions in your Views.
*/
register() {
KnockoutComposition.prototype.register = function () {
var _this = this;
// a bit hacky, I know ;)
if (typeof window !== "undefined") {
window.ko = ko;
}
ko.bindingHandlers.compose = {
update: (element, valueAccessor, allBindings, viewModel) => {
let value = valueAccessor();
update: function (element, valueAccessor, allBindings, viewModel) {
var value = valueAccessor();
if (element.childElementCount > 0) {
// Remove previous composed view
callEvent(element, 'detached', [element, element.parentElement]);
while (element.firstChild) {
element.removeChild(element.firstChild);
}
}
doComposition.call(this, element, ko.unwrap(value), viewModel);
doComposition.call(_this, element, ko.unwrap(value), viewModel);
}
};
ko.virtualElements.allowedBindings["compose"] = true;
}
};
/** internal: do not use */
buildCompositionSettings(value, bindingContext) {
let view = null;
let moduleId = null;
let viewModel;
let activationData;
KnockoutComposition.prototype.buildCompositionSettings = function (value, bindingContext) {
var view = null;
var moduleId = null;
var viewModel = null;
var activationData = null;
// See http://durandaljs.com/documentation/Using-Composition.html
if (typeof value === 'string') {
if (endsWith(value, '.html')) {
Expand Down Expand Up @@ -130,23 +134,24 @@ define(["require", "exports", "knockout", "aurelia-dependency-injection", "aurel
// Call the constructor
viewModel = value();
}
let settings = { view: view, viewModel: viewModel, model: activationData };
var settings = { view: view, viewModel: viewModel, model: activationData };
if (!viewModel && moduleId) {
return this.getViewModelInstance(moduleId).then((modelInstance) => {
return this.getViewModelInstance(moduleId).then(function (modelInstance) {
settings.viewModel = modelInstance;
return Promise.resolve(settings);
});
}
return Promise.resolve(settings);
}
};
/** internal: do not use */
getViewModelInstance(moduleId) {
let index = moduleId.lastIndexOf("/");
let fileName = moduleId.substr(index === -1 ? 0 : index + 1).toLowerCase();
return loadModule(moduleId, this.loader).then((result) => {
KnockoutComposition.prototype.getViewModelInstance = function (moduleId) {
var _this = this;
var index = moduleId.lastIndexOf("/");
var fileName = moduleId.substr(index === -1 ? 0 : index + 1).toLowerCase();
return loadModule(moduleId, this.loader).then(function (result) {
if (typeof result !== 'function') {
// Try to find a property which name matches the filename of the module
let constructorPropName = getMatchingProperty(result, fileName);
var constructorPropName = getMatchingProperty(result, fileName);
if (constructorPropName) {
// Use function of property.
// This occurs if the constructor function is exported by the module.
Expand All @@ -157,10 +162,11 @@ define(["require", "exports", "knockout", "aurelia-dependency-injection", "aurel
return result;
}
}
return this.container.get(result);
return _this.container.get(result);
});
}
};
};
return KnockoutComposition;
}());
KnockoutComposition = __decorate([
aurelia_dependency_injection_1.inject(aurelia_templating_1.CompositionEngine, aurelia_dependency_injection_1.Container, aurelia_loader_1.Loader)
], KnockoutComposition);
Expand Down
20 changes: 11 additions & 9 deletions dist/amd/knockout-custom-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
};
define(["require", "exports", "aurelia-dependency-injection", "aurelia-templating", "knockout"], function (require, exports, aurelia_dependency_injection_1, aurelia_templating_1, ko) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function getFirstBoundChild(rootNode) {
var data = ko.dataFor(rootNode);
if (data) {
Expand All @@ -20,20 +21,20 @@ define(["require", "exports", "aurelia-dependency-injection", "aurelia-templatin
}
return null;
}
let KnockoutCustomAttribute = class KnockoutCustomAttribute {
constructor(element) {
var KnockoutCustomAttribute = (function () {
function KnockoutCustomAttribute(element) {
this.element = element;
}
static register() {
KnockoutCustomAttribute.register = function () {
ko.bindingHandlers.stopKoBinding = {
init: function () {
return { controlsDescendantBindings: true };
}
};
ko.virtualElements.allowedBindings.stopKoBinding = true;
}
};
/** internal: do not use */
bind(executionContext) {
KnockoutCustomAttribute.prototype.bind = function (executionContext) {
var data = getFirstBoundChild(this.element);
if (data) {
var startComment = document.createComment(" ko stopKoBinding: true ");
Expand All @@ -45,12 +46,13 @@ define(["require", "exports", "aurelia-dependency-injection", "aurelia-templatin
}
}
ko.applyBindings(executionContext, this.element);
}
};
/** internal: do not use */
unbind() {
KnockoutCustomAttribute.prototype.unbind = function () {
ko.cleanNode(this.element);
}
};
};
return KnockoutCustomAttribute;
}());
KnockoutCustomAttribute = __decorate([
aurelia_templating_1.customAttribute('knockout'),
aurelia_dependency_injection_1.inject(Element)
Expand Down
27 changes: 15 additions & 12 deletions dist/amd/require-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,31 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
};
define(["require", "exports", "aurelia-loader", "aurelia-dependency-injection"], function (require, exports, aurelia_loader_1, aurelia_dependency_injection_1) {
"use strict";
let RequirePolyfill = class RequirePolyfill {
constructor(loader) {
Object.defineProperty(exports, "__esModule", { value: true });
var RequirePolyfill = (function () {
function RequirePolyfill(loader) {
this.loader = loader;
}
/**
* Registers the `require` function if not set.
*/
register() {
RequirePolyfill.prototype.register = function () {
var _this = this;
var w = window;
if (!w.require) {
w.require = (modulesToLoad, callback) => {
w.require = function (modulesToLoad, callback) {
var promises = [];
modulesToLoad.forEach((module) => {
modulesToLoad.forEach(function (module) {
if (module.startsWith("text!")) {
promises.push(this.loader.loadText(module.substr(5)));
promises.push(_this.loader.loadText(module.substr(5)));
}
else {
promises.push(this.loader.loadModule(module));
promises.push(_this.loader.loadModule(module));
}
});
Promise.all(promises).then((r) => {
Promise.all(promises).then(function (r) {
var results = [];
r.forEach((element) => {
r.forEach(function (element) {
var props = Object.keys(element);
if (props.length === 1 && typeof element[props[0]] === "function") {
results.push(element[props[0]]);
Expand All @@ -37,12 +39,13 @@ define(["require", "exports", "aurelia-loader", "aurelia-dependency-injection"],
results.push(element);
}
});
callback.apply(this, results);
callback.apply(_this, results);
});
};
}
}
};
};
return RequirePolyfill;
}());
RequirePolyfill = __decorate([
aurelia_dependency_injection_1.inject(aurelia_loader_1.Loader)
], RequirePolyfill);
Expand Down
10 changes: 6 additions & 4 deletions dist/commonjs/aurelia-knockout.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
var aurelia_pal_1 = require("aurelia-pal");
__export(require("./knockout-bindable"));
__export(require("./knockout-composition"));
__export(require("./knockout-custom-attribute"));
__export(require("./require-polyfill"));
const knockout_custom_attribute_1 = require("./knockout-custom-attribute");
const knockout_composition_1 = require("./knockout-composition");
const require_polyfill_1 = require("./require-polyfill");
var knockout_custom_attribute_1 = require("./knockout-custom-attribute");
var knockout_composition_1 = require("./knockout-composition");
var require_polyfill_1 = require("./require-polyfill");
function configure(frameworkConfig) {
// register custom attribute
frameworkConfig.globalResources('./knockout-custom-attribute');
frameworkConfig.globalResources(aurelia_pal_1.PLATFORM.moduleName('./knockout-custom-attribute'));
// register knockout custom binding for composition logic
frameworkConfig.container.get(knockout_composition_1.KnockoutComposition).register();
// register require function in window object if not available
Expand Down
Loading

0 comments on commit 61c0e2b

Please sign in to comment.