Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrated with aurelia framework 1.0.0-beta.1.0.1 #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/amd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ define(['exports', './lifecycle-manager', './router', './instance-dispatcher', '
exports.waitFor = _decoratorsWaitFor.waitFor;

function configure(aurelia, configCallback) {
_lifecycleManager.LifecycleManager.interceptClassActivator();
_lifecycleManager.LifecycleManager.interceptClassActivator(aurelia);
_lifecycleManager.LifecycleManager.interceptHtmlBehaviorResource();
_router.RouterManager.AddFluxPipelineStep(aurelia);
}
Expand Down
12 changes: 10 additions & 2 deletions dist/amd/lifecycle-manager.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare module 'aurelia-flux' {
import { ClassActivator } from 'aurelia-dependency-injection';
import { resolver } from 'aurelia-dependency-injection';
import { HtmlBehaviorResource } from 'aurelia-templating';
import { Dispatcher, DispatcherProxy } from 'aurelia-flux/instance-dispatcher';
import { FluxDispatcher } from 'aurelia-flux/flux-dispatcher';
Expand All @@ -12,6 +12,14 @@ declare module 'aurelia-flux' {
static interceptInstanceDeactivate(instance: any): any;
static interceptInstanceDetached(instance: any): any;
static interceptHtmlBehaviorResource(): any;
static interceptClassActivator(): any;
static interceptClassActivator(aurelia: any): any;
}
class DispatcherResolver {
get(container: any): any;
}
class InstanceDispatcher {
obj: any;
dispatch(method: any, ...payload: any[]): any;
connect(instance: any): any;
}
}
117 changes: 76 additions & 41 deletions dist/amd/lifecycle-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-templating', './inst
};

LifecycleManager.interceptHtmlBehaviorResource = function interceptHtmlBehaviorResource() {
if (_aureliaTemplating.HtmlBehaviorResource === undefined || typeof _aureliaTemplating.HtmlBehaviorResource.prototype.analyze !== 'function') {
if (_aureliaTemplating.HtmlBehaviorResource === undefined || typeof _aureliaTemplating.HtmlBehaviorResource.prototype.initialize !== 'function') {
throw new Error('Unsupported version of HtmlBehaviorResource');
}

var analyzeImpl = _aureliaTemplating.HtmlBehaviorResource.prototype.analyze;
var analyzeImpl = _aureliaTemplating.HtmlBehaviorResource.prototype.initialize;

_aureliaTemplating.HtmlBehaviorResource.prototype.analyze = function () {
_aureliaTemplating.HtmlBehaviorResource.prototype.initialize = function () {
for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
Expand All @@ -92,55 +92,90 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-templating', './inst
};
};

LifecycleManager.interceptClassActivator = function interceptClassActivator() {
if (_aureliaDependencyInjection.ClassActivator.instance === undefined || _aureliaDependencyInjection.ClassActivator.instance.invoke === undefined) {
throw new Error('Unsupported version of ClassActivator');
}

var invokeImpl = _aureliaDependencyInjection.ClassActivator.instance.invoke;
_aureliaDependencyInjection.ClassActivator.instance.invoke = function () {
for (var _len4 = arguments.length, invokeArgs = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
invokeArgs[_key4] = arguments[_key4];
}
LifecycleManager.interceptClassActivator = function interceptClassActivator(aurelia) {
aurelia.container.setHandlerCreatedCallback(function (handler) {

var args = invokeArgs[1],
instance;

if (Array.isArray(args) === false) {
throw new Error('Unsupported version of ClassActivator');
}

var dispatcher = args.find(function (item) {
return item instanceof _instanceDispatcher.Dispatcher;
});

if (dispatcher) {
var instancePromise = _Promise['default'].defer();
args[args.indexOf(dispatcher)] = new _instanceDispatcher.DispatcherProxy(instancePromise.promise);
instance = invokeImpl.apply(this, invokeArgs);
instance[_symbols.Symbols.instanceDispatcher] = new _instanceDispatcher.Dispatcher(instance);
instancePromise.resolve(instance);
} else {
instance = invokeImpl.apply(this, invokeArgs);
}
var index = handler.dependencies.indexOf(_instanceDispatcher.Dispatcher);

if (_metadata.Metadata.exists(Object.getPrototypeOf(instance))) {
if (instance[_symbols.Symbols.instanceDispatcher] === undefined) {
instance[_symbols.Symbols.instanceDispatcher] = new _instanceDispatcher.Dispatcher(instance);
if (index == -1) {
for (var i = 0; i < handler.dependencies.length; i++) {
if (handler.dependencies[i] instanceof DispatcherResolver) index = i;
}
instance[_symbols.Symbols.instanceDispatcher].registerMetadata();
}

if (instance[_symbols.Symbols.instanceDispatcher] !== undefined) {
LifecycleManager.interceptInstanceDeactivators(instance);
if (index !== -1) {
(function () {
handler.dependencies[index] = new DispatcherResolver();

var invoke = handler.invoke;
handler.invoke = function (container, dynamicDependencies) {
var instance = invoke.call(handler, container, dynamicDependencies);
try {
if (container._lastDispatcher == null) instance.dispatcher.connect(instance);else container._lastDispatcher.connect(instance);
container._lastDispatcher = null;
} catch (e) {
console.log(e);
}
return instance;
};
})();
}

return instance;
};
return handler;
});
};

return LifecycleManager;
})();

exports.LifecycleManager = LifecycleManager;

var DispatcherResolver = (function () {
function DispatcherResolver() {
_classCallCheck(this, _DispatcherResolver);
}

DispatcherResolver.prototype.get = function get(container) {
return container._lastDispatcher = container.get(InstanceDispatcher);
};

var _DispatcherResolver = DispatcherResolver;
DispatcherResolver = _aureliaDependencyInjection.resolver(DispatcherResolver) || DispatcherResolver;
return DispatcherResolver;
})();

var InstanceDispatcher = (function () {
function InstanceDispatcher() {
_classCallCheck(this, InstanceDispatcher);
}

InstanceDispatcher.prototype.dispatch = function dispatch(method) {
var _obj;

for (var _len4 = arguments.length, payload = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
payload[_key4 - 1] = arguments[_key4];
}

(_obj = this.obj).dispatch.apply(_obj, [method].concat(payload));
};

InstanceDispatcher.prototype.connect = function connect(instance) {

if (_metadata.Metadata.exists(Object.getPrototypeOf(instance))) {
if (instance[_symbols.Symbols.instanceDispatcher] === undefined) {
instance[_symbols.Symbols.instanceDispatcher] = new _instanceDispatcher.Dispatcher(instance);
this.obj = instance[_symbols.Symbols.instanceDispatcher];
}
instance[_symbols.Symbols.instanceDispatcher].registerMetadata();
}

if (instance[_symbols.Symbols.instanceDispatcher] !== undefined) {
LifecycleManager.interceptInstanceDeactivators(instance);
}

return instance;
};

return InstanceDispatcher;
})();
});
1 change: 1 addition & 0 deletions dist/amd/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ define(['exports', 'aurelia-router', './flux-dispatcher'], function (exports, _a
var router = aurelia.container.get(_aureliaRouter.Router);
var configuration = new _aureliaRouter.RouterConfiguration();

router.container = aurelia.container;
configuration.addPipelineStep("modelbind", FluxLifeCycleStep);
router.configure(configuration);
};
Expand Down
2 changes: 1 addition & 1 deletion dist/commonjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var _decoratorsWaitFor = require('./decorators/waitFor');
exports.waitFor = _decoratorsWaitFor.waitFor;

function configure(aurelia, configCallback) {
_lifecycleManager.LifecycleManager.interceptClassActivator();
_lifecycleManager.LifecycleManager.interceptClassActivator(aurelia);
_lifecycleManager.LifecycleManager.interceptHtmlBehaviorResource();
_router.RouterManager.AddFluxPipelineStep(aurelia);
}
12 changes: 10 additions & 2 deletions dist/commonjs/lifecycle-manager.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare module 'aurelia-flux' {
import { ClassActivator } from 'aurelia-dependency-injection';
import { resolver } from 'aurelia-dependency-injection';
import { HtmlBehaviorResource } from 'aurelia-templating';
import { Dispatcher, DispatcherProxy } from 'aurelia-flux/instance-dispatcher';
import { FluxDispatcher } from 'aurelia-flux/flux-dispatcher';
Expand All @@ -12,6 +12,14 @@ declare module 'aurelia-flux' {
static interceptInstanceDeactivate(instance: any): any;
static interceptInstanceDetached(instance: any): any;
static interceptHtmlBehaviorResource(): any;
static interceptClassActivator(): any;
static interceptClassActivator(aurelia: any): any;
}
class DispatcherResolver {
get(container: any): any;
}
class InstanceDispatcher {
obj: any;
dispatch(method: any, ...payload: any[]): any;
connect(instance: any): any;
}
}
117 changes: 76 additions & 41 deletions dist/commonjs/lifecycle-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ var LifecycleManager = (function () {
};

LifecycleManager.interceptHtmlBehaviorResource = function interceptHtmlBehaviorResource() {
if (_aureliaTemplating.HtmlBehaviorResource === undefined || typeof _aureliaTemplating.HtmlBehaviorResource.prototype.analyze !== 'function') {
if (_aureliaTemplating.HtmlBehaviorResource === undefined || typeof _aureliaTemplating.HtmlBehaviorResource.prototype.initialize !== 'function') {
throw new Error('Unsupported version of HtmlBehaviorResource');
}

var analyzeImpl = _aureliaTemplating.HtmlBehaviorResource.prototype.analyze;
var analyzeImpl = _aureliaTemplating.HtmlBehaviorResource.prototype.initialize;

_aureliaTemplating.HtmlBehaviorResource.prototype.analyze = function () {
_aureliaTemplating.HtmlBehaviorResource.prototype.initialize = function () {
for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
Expand All @@ -107,54 +107,89 @@ var LifecycleManager = (function () {
};
};

LifecycleManager.interceptClassActivator = function interceptClassActivator() {
if (_aureliaDependencyInjection.ClassActivator.instance === undefined || _aureliaDependencyInjection.ClassActivator.instance.invoke === undefined) {
throw new Error('Unsupported version of ClassActivator');
}
LifecycleManager.interceptClassActivator = function interceptClassActivator(aurelia) {
aurelia.container.setHandlerCreatedCallback(function (handler) {

var invokeImpl = _aureliaDependencyInjection.ClassActivator.instance.invoke;
_aureliaDependencyInjection.ClassActivator.instance.invoke = function () {
for (var _len4 = arguments.length, invokeArgs = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
invokeArgs[_key4] = arguments[_key4];
}
var index = handler.dependencies.indexOf(_instanceDispatcher.Dispatcher);

var args = invokeArgs[1],
instance;
if (index == -1) {
for (var i = 0; i < handler.dependencies.length; i++) {
if (handler.dependencies[i] instanceof DispatcherResolver) index = i;
}
}

if (Array.isArray(args) === false) {
throw new Error('Unsupported version of ClassActivator');
if (index !== -1) {
(function () {
handler.dependencies[index] = new DispatcherResolver();

var invoke = handler.invoke;
handler.invoke = function (container, dynamicDependencies) {
var instance = invoke.call(handler, container, dynamicDependencies);
try {
if (container._lastDispatcher == null) instance.dispatcher.connect(instance);else container._lastDispatcher.connect(instance);
container._lastDispatcher = null;
} catch (e) {
console.log(e);
}
return instance;
};
})();
}

var dispatcher = args.find(function (item) {
return item instanceof _instanceDispatcher.Dispatcher;
});
return handler;
});
};

if (dispatcher) {
var instancePromise = _bluebird2['default'].defer();
args[args.indexOf(dispatcher)] = new _instanceDispatcher.DispatcherProxy(instancePromise.promise);
instance = invokeImpl.apply(this, invokeArgs);
instance[_symbols.Symbols.instanceDispatcher] = new _instanceDispatcher.Dispatcher(instance);
instancePromise.resolve(instance);
} else {
instance = invokeImpl.apply(this, invokeArgs);
}
return LifecycleManager;
})();

if (_metadata.Metadata.exists(Object.getPrototypeOf(instance))) {
if (instance[_symbols.Symbols.instanceDispatcher] === undefined) {
instance[_symbols.Symbols.instanceDispatcher] = new _instanceDispatcher.Dispatcher(instance);
}
instance[_symbols.Symbols.instanceDispatcher].registerMetadata();
}
exports.LifecycleManager = LifecycleManager;

if (instance[_symbols.Symbols.instanceDispatcher] !== undefined) {
LifecycleManager.interceptInstanceDeactivators(instance);
}
var DispatcherResolver = (function () {
function DispatcherResolver() {
_classCallCheck(this, _DispatcherResolver);
}

return instance;
};
DispatcherResolver.prototype.get = function get(container) {
return container._lastDispatcher = container.get(InstanceDispatcher);
};

return LifecycleManager;
var _DispatcherResolver = DispatcherResolver;
DispatcherResolver = _aureliaDependencyInjection.resolver(DispatcherResolver) || DispatcherResolver;
return DispatcherResolver;
})();

exports.LifecycleManager = LifecycleManager;
var InstanceDispatcher = (function () {
function InstanceDispatcher() {
_classCallCheck(this, InstanceDispatcher);
}

InstanceDispatcher.prototype.dispatch = function dispatch(method) {
var _obj;

for (var _len4 = arguments.length, payload = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
payload[_key4 - 1] = arguments[_key4];
}

(_obj = this.obj).dispatch.apply(_obj, [method].concat(payload));
};

InstanceDispatcher.prototype.connect = function connect(instance) {

if (_metadata.Metadata.exists(Object.getPrototypeOf(instance))) {
if (instance[_symbols.Symbols.instanceDispatcher] === undefined) {
instance[_symbols.Symbols.instanceDispatcher] = new _instanceDispatcher.Dispatcher(instance);
this.obj = instance[_symbols.Symbols.instanceDispatcher];
}
instance[_symbols.Symbols.instanceDispatcher].registerMetadata();
}

if (instance[_symbols.Symbols.instanceDispatcher] !== undefined) {
LifecycleManager.interceptInstanceDeactivators(instance);
}

return instance;
};

return InstanceDispatcher;
})();
1 change: 1 addition & 0 deletions dist/commonjs/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var RouterManager = (function () {
var router = aurelia.container.get(_aureliaRouter.Router);
var configuration = new _aureliaRouter.RouterConfiguration();

router.container = aurelia.container;
configuration.addPipelineStep("modelbind", FluxLifeCycleStep);
router.configure(configuration);
};
Expand Down
3 changes: 2 additions & 1 deletion dist/es6/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {LifecycleManager} from './lifecycle-manager';
import {RouterManager} from './router';

export function configure(aurelia, configCallback) {
LifecycleManager.interceptClassActivator();
//aurelia.container.makeGlobal();
LifecycleManager.interceptClassActivator(aurelia);
LifecycleManager.interceptHtmlBehaviorResource();
RouterManager.AddFluxPipelineStep(aurelia);
}
Loading