Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "format register";
- System.register("jiff/di/util", [], function($__export) {
- "use strict";
- var __moduleName = "jiff/di/util";
- function isUpperCase(char) {
- return char.toUpperCase() === char;
- }
- function isClass(clsOrFunction) {
- if (clsOrFunction.name) {
- return isUpperCase(clsOrFunction.name.charAt(0));
- }
- return Object.keys(clsOrFunction.prototype).length > 0;
- }
- function isFunction(value) {
- return typeof value === 'function';
- }
- function isObject(value) {
- return typeof value === 'object';
- }
- function toString(token) {
- if (typeof token === 'string') {
- return token;
- }
- if (token === undefined || token === null) {
- return '' + token;
- }
- if (token.name) {
- return token.name;
- }
- return token.toString();
- }
- return {
- setters: [],
- execute: function() {
- $__export("isUpperCase", isUpperCase), $__export("isClass", isClass), $__export("isFunction", isFunction), $__export("isObject", isObject), $__export("toString", toString);
- }
- };
- });
- System.register("jiff/di/profiler", ["./util"], function($__export) {
- "use strict";
- var __moduleName = "jiff/di/profiler";
- var toString,
- IS_DEBUG,
- _global,
- globalCounter;
- function getUniqueId() {
- return ++globalCounter;
- }
- function serializeToken(token, tokens) {
- if (!tokens.has(token)) {
- tokens.set(token, getUniqueId().toString());
- }
- return tokens.get(token);
- }
- function serializeProvider(provider, key, tokens) {
- return {
- id: serializeToken(key, tokens),
- name: toString(key),
- isPromise: provider.isPromise,
- dependencies: provider.params.map(function(param) {
- return {
- token: serializeToken(param.token, tokens),
- isPromise: param.isPromise,
- isLazy: param.isLazy
- };
- })
- };
- }
- function serializeInjector(injector, tokens, Injector) {
- var serializedInjector = {
- id: serializeToken(injector, tokens),
- parent_id: injector.parent ? serializeToken(injector.parent, tokens) : null,
- providers: {}
- };
- var injectorClassId = serializeToken(Injector, tokens);
- serializedInjector.providers[injectorClassId] = {
- id: injectorClassId,
- name: toString(Injector),
- isPromise: false,
- dependencies: []
- };
- injector.providers.forEach(function(provider, key) {
- var serializedProvider = serializeProvider(provider, key, tokens);
- serializedInjector.providers[serializedProvider.id] = serializedProvider;
- });
- return serializedInjector;
- }
- function profileInjector(injector, Injector) {
- if (!IS_DEBUG) {
- return ;
- }
- if (!_global.__di_dump__) {
- _global.__di_dump__ = {
- injectors: [],
- tokens: new Map()
- };
- }
- _global.__di_dump__.injectors.push(serializeInjector(injector, _global.__di_dump__.tokens, Injector));
- }
- $__export("profileInjector", profileInjector);
- return {
- setters: [function($__m) {
- toString = $__m.toString;
- }],
- execute: function() {
- IS_DEBUG = false;
- _global = null;
- if (typeof process === 'object' && process.env) {
- IS_DEBUG = !!process.env['DEBUG'];
- _global = global;
- } else if (typeof location === 'object' && location.search) {
- IS_DEBUG = /di_debug/.test(location.search);
- _global = window;
- }
- globalCounter = 0;
- }
- };
- });
- System.register("jiff/di/providers", ["./annotations", "./util"], function($__export) {
- "use strict";
- var __moduleName = "jiff/di/providers";
- var SuperConstructorAnnotation,
- readAnnotations,
- isClass,
- isFunction,
- isObject,
- toString,
- EmptyFunction,
- ClassProvider,
- FactoryProvider,
- ValueProvider;
- function createProviderFromFnOrClass(fnOrClass, annotations) {
- if (isClass(fnOrClass)) {
- return new ClassProvider(fnOrClass, annotations.params, annotations.provide.isPromise);
- }
- return new FactoryProvider(fnOrClass, annotations.params, annotations.provide.isPromise);
- }
- function createProviderFromValue(value) {
- return new ValueProvider(value);
- }
- $__export("createProviderFromFnOrClass", createProviderFromFnOrClass);
- $__export("createProviderFromValue", createProviderFromValue);
- return {
- setters: [function($__m) {
- SuperConstructorAnnotation = $__m.SuperConstructor;
- readAnnotations = $__m.readAnnotations;
- }, function($__m) {
- isClass = $__m.isClass;
- isFunction = $__m.isFunction;
- isObject = $__m.isObject;
- toString = $__m.toString;
- }],
- execute: function() {
- EmptyFunction = Object.getPrototypeOf(Function);
- ClassProvider = (function() {
- var ClassProvider = function ClassProvider(clazz, params, isPromise) {
- this.provider = clazz;
- this.isPromise = isPromise;
- this.params = [];
- this.constructors = [];
- this._flattenParams(clazz, params);
- this.constructors.unshift([clazz, 0, this.params.length - 1]);
- };
- return ($traceurRuntime.createClass)(ClassProvider, {
- _flattenParams: function(constructor, params) {
- var SuperConstructor;
- var constructorInfo;
- for (var $__1 = params[$traceurRuntime.toProperty(Symbol.iterator)](),
- $__2 = void 0; !($__2 = $__1.next()).done; ) {
- var param = $__2.value;
- {
- if (param.token === SuperConstructorAnnotation) {
- SuperConstructor = Object.getPrototypeOf(constructor);
- if (SuperConstructor === EmptyFunction) {
- throw new Error((toString(constructor) + " does not have a parent constructor. Only classes with a parent can ask for SuperConstructor!"));
- }
- constructorInfo = [SuperConstructor, this.params.length];
- this.constructors.push(constructorInfo);
- this._flattenParams(SuperConstructor, readAnnotations(SuperConstructor).params);
- constructorInfo.push(this.params.length - 1);
- } else {
- this.params.push(param);
- }
- }
- }
- },
- _createConstructor: function(currentConstructorIdx, context, allArguments) {
- var constructorInfo = this.constructors[currentConstructorIdx];
- var nextConstructorInfo = this.constructors[currentConstructorIdx + 1];
- var argsForCurrentConstructor;
- if (nextConstructorInfo) {
- argsForCurrentConstructor = allArguments.slice(constructorInfo[1], nextConstructorInfo[1]).concat([this._createConstructor(currentConstructorIdx + 1, context, allArguments)]).concat(allArguments.slice(nextConstructorInfo[2] + 1, constructorInfo[2] + 1));
- } else {
- argsForCurrentConstructor = allArguments.slice(constructorInfo[1], constructorInfo[2] + 1);
- }
- return function InjectedAndBoundSuperConstructor() {
- return constructorInfo[0].apply(context, argsForCurrentConstructor);
- };
- },
- create: function(args) {
- var context = Object.create(this.provider.prototype);
- var constructor = this._createConstructor(0, context, args);
- var returnedValue = constructor();
- if (isFunction(returnedValue) || isObject(returnedValue)) {
- return returnedValue;
- }
- return context;
- }
- }, {});
- }());
- FactoryProvider = (function() {
- var FactoryProvider = function FactoryProvider(factoryFunction, params, isPromise) {
- this.provider = factoryFunction;
- this.params = params;
- this.isPromise = isPromise;
- for (var $__1 = params[$traceurRuntime.toProperty(Symbol.iterator)](),
- $__2 = void 0; !($__2 = $__1.next()).done; ) {
- var param = $__2.value;
- {
- if (param.token === SuperConstructorAnnotation) {
- throw new Error((toString(factoryFunction) + " is not a class. Only classes with a parent can ask for SuperConstructor!"));
- }
- }
- }
- };
- return ($traceurRuntime.createClass)(FactoryProvider, {create: function(args) {
- return this.provider.apply(undefined, args);
- }}, {});
- }());
- ValueProvider = (function() {
- var ValueProvider = function ValueProvider(value) {
- this.provider = function() {};
- this.params = [];
- this.isPromise = false;
- this._value = value;
- };
- return ($traceurRuntime.createClass)(ValueProvider, {create: function() {
- return this._value;
- }}, {});
- }());
- }
- };
- });
- System.register("jiff/di/annotations", ["./util"], function($__export) {
- "use strict";
- var __moduleName = "jiff/di/annotations";
- var isFunction,
- SuperConstructor,
- TransientScope,
- Inject,
- InjectPromise,
- InjectLazy,
- Provide,
- ProvidePromise;
- function annotate(fn, annotation) {
- fn.annotations = fn.annotations || [];
- fn.annotations.push(annotation);
- }
- function hasAnnotation(fn, annotationClass) {
- if (!fn.annotations || fn.annotations.length === 0) {
- return false;
- }
- for (var $__1 = fn.annotations[$traceurRuntime.toProperty(Symbol.iterator)](),
- $__2 = void 0; !($__2 = $__1.next()).done; ) {
- var annotation = $__2.value;
- {
- if (annotation instanceof annotationClass) {
- return true;
- }
- }
- }
- return false;
- }
- function hasParameterAnnotation(fn, AnnotationClass) {
- if (!fn.parameters || fn.parameters.length === 0) {
- return false;
- }
- for (var $__3 = fn.parameters[$traceurRuntime.toProperty(Symbol.iterator)](),
- $__4 = void 0; !($__4 = $__3.next()).done; ) {
- var parameterAnnotations = $__4.value;
- {
- for (var $__1 = parameterAnnotations[$traceurRuntime.toProperty(Symbol.iterator)](),
- $__2 = void 0; !($__2 = $__1.next()).done; ) {
- var annotation = $__2.value;
- {
- if (annotation instanceof AnnotationClass) {
- return true;
- }
- }
- }
- }
- }
- return false;
- }
- function readAnnotations(fn) {
- var collectedAnnotations = {
- provide: {
- token: null,
- isPromise: false
- },
- params: []
- };
- if (fn.annotations && fn.annotations.length) {
- for (var $__1 = fn.annotations[$traceurRuntime.toProperty(Symbol.iterator)](),
- $__2 = void 0; !($__2 = $__1.next()).done; ) {
- var annotation = $__2.value;
- {
- if (annotation instanceof Inject) {
- collectedAnnotations.params = annotation.tokens.map((function(token) {
- return {
- token: token,
- isPromise: annotation.isPromise,
- isLazy: annotation.isLazy
- };
- }));
- }
- if (annotation instanceof Provide) {
- collectedAnnotations.provide.token = annotation.token;
- collectedAnnotations.provide.isPromise = annotation.isPromise;
- }
- }
- }
- }
- if (fn.parameters) {
- fn.parameters.forEach((function(param, idx) {
- for (var $__3 = param[$traceurRuntime.toProperty(Symbol.iterator)](),
- $__4 = void 0; !($__4 = $__3.next()).done; ) {
- var paramAnnotation = $__4.value;
- {
- if (isFunction(paramAnnotation) && !collectedAnnotations.params[idx]) {
- collectedAnnotations.params[idx] = {
- token: paramAnnotation,
- isPromise: false,
- isLazy: false
- };
- } else if (paramAnnotation instanceof Inject) {
- collectedAnnotations.params[idx] = {
- token: paramAnnotation.tokens[0],
- isPromise: paramAnnotation.isPromise,
- isLazy: paramAnnotation.isLazy
- };
- }
- }
- }
- }));
- }
- return collectedAnnotations;
- }
- return {
- setters: [function($__m) {
- isFunction = $__m.isFunction;
- }],
- execute: function() {
- SuperConstructor = (function() {
- var SuperConstructor = function SuperConstructor() {};
- return ($traceurRuntime.createClass)(SuperConstructor, {}, {});
- }());
- TransientScope = (function() {
- var TransientScope = function TransientScope() {};
- return ($traceurRuntime.createClass)(TransientScope, {}, {});
- }());
- Inject = (function() {
- var Inject = function Inject() {
- for (var tokens = [],
- $__5 = 0; $__5 < arguments.length; $__5++)
- tokens[$__5] = arguments[$__5];
- this.tokens = tokens;
- this.isPromise = false;
- this.isLazy = false;
- };
- return ($traceurRuntime.createClass)(Inject, {}, {});
- }());
- InjectPromise = (function($__super) {
- var InjectPromise = function InjectPromise() {
- var $__6;
- for (var tokens = [],
- $__5 = 0; $__5 < arguments.length; $__5++)
- tokens[$__5] = arguments[$__5];
- ($__6 = $traceurRuntime.superConstructor(InjectPromise)).call.apply($__6, $traceurRuntime.spread([this], tokens));
- this.tokens = tokens;
- this.isPromise = true;
- this.isLazy = false;
- };
- return ($traceurRuntime.createClass)(InjectPromise, {}, {}, $__super);
- }(Inject));
- InjectLazy = (function($__super) {
- var InjectLazy = function InjectLazy() {
- var $__6;
- for (var tokens = [],
- $__5 = 0; $__5 < arguments.length; $__5++)
- tokens[$__5] = arguments[$__5];
- ($__6 = $traceurRuntime.superConstructor(InjectLazy)).call.apply($__6, $traceurRuntime.spread([this], tokens));
- this.tokens = tokens;
- this.isPromise = false;
- this.isLazy = true;
- };
- return ($traceurRuntime.createClass)(InjectLazy, {}, {}, $__super);
- }(Inject));
- Provide = (function() {
- var Provide = function Provide(token) {
- this.token = token;
- this.isPromise = false;
- };
- return ($traceurRuntime.createClass)(Provide, {}, {});
- }());
- ProvidePromise = (function($__super) {
- var ProvidePromise = function ProvidePromise(token) {
- $traceurRuntime.superConstructor(ProvidePromise).call(this, token);
- this.token = token;
- this.isPromise = true;
- };
- return ($traceurRuntime.createClass)(ProvidePromise, {}, {}, $__super);
- }(Provide));
- $__export("annotate", annotate), $__export("hasAnnotation", hasAnnotation), $__export("hasParameterAnnotation", hasParameterAnnotation), $__export("readAnnotations", readAnnotations), $__export("SuperConstructor", SuperConstructor), $__export("TransientScope", TransientScope), $__export("Inject", Inject), $__export("InjectPromise", InjectPromise), $__export("InjectLazy", InjectLazy), $__export("Provide", Provide), $__export("ProvidePromise", ProvidePromise);
- }
- };
- });
- System.register("jiff/di/injector", ["./annotations", "./util", "./profiler", "./providers"], function($__export) {
- "use strict";
- var __moduleName = "jiff/di/injector";
- var annotate,
- readAnnotations,
- hasAnnotation,
- hasParameterAnnotation,
- ProvideAnnotation,
- InjectAnnotation,
- TransientScopeAnnotation,
- isFunction,
- isObject,
- toString,
- profileInjector,
- createProviderFromFnOrClass,
- createProviderFromValue,
- Injector;
- function constructResolvingMessage(resolving, token) {
- if (arguments.length > 1) {
- resolving.push(token);
- }
- if (resolving.length > 1) {
- return (" (" + resolving.map(toString).join(' -> ') + ")");
- }
- return '';
- }
- return {
- setters: [function($__m) {
- annotate = $__m.annotate;
- readAnnotations = $__m.readAnnotations;
- hasAnnotation = $__m.hasAnnotation;
- hasParameterAnnotation = $__m.hasParameterAnnotation;
- ProvideAnnotation = $__m.Provide;
- InjectAnnotation = $__m.Inject;
- TransientScopeAnnotation = $__m.TransientScope;
- }, function($__m) {
- isFunction = $__m.isFunction;
- isObject = $__m.isObject;
- toString = $__m.toString;
- }, function($__m) {
- profileInjector = $__m.profileInjector;
- }, function($__m) {
- createProviderFromFnOrClass = $__m.createProviderFromFnOrClass;
- createProviderFromValue = $__m.createProviderFromValue;
- }],
- execute: function() {
- Injector = (function() {
- var Injector = function Injector() {
- var modules = arguments[0] !== (void 0) ? arguments[0] : [];
- var parentInjector = arguments[1] !== (void 0) ? arguments[1] : null;
- var providers = arguments[2] !== (void 0) ? arguments[2] : new Map();
- this.cache = new Map();
- this.providers = providers;
- this.parent = parentInjector;
- this._loadModules(modules);
- profileInjector(this, Injector);
- };
- return ($traceurRuntime.createClass)(Injector, {
- _collectProvidersWithAnnotation: function(annotationClass, collectedProviders) {
- this.providers.forEach((function(provider, token) {
- if (!collectedProviders.has(token) && hasAnnotation(provider.provider, annotationClass)) {
- collectedProviders.set(token, provider);
- }
- }));
- if (this.parent) {
- this.parent._collectProvidersWithAnnotation(annotationClass, collectedProviders);
- }
- },
- _loadModules: function(modules) {
- for (var $__2 = modules[$traceurRuntime.toProperty(Symbol.iterator)](),
- $__3 = void 0; !($__3 = $__2.next()).done; ) {
- var module = $__3.value;
- {
- if (isFunction(module)) {
- this._loadFnOrClass(module);
- continue;
- }
- throw new Error('Invalid module!');
- }
- }
- },
- _loadFnOrClass: function(fnOrClass) {
- var annotations = readAnnotations(fnOrClass);
- var token = annotations.provide.token || fnOrClass;
- var provider = createProviderFromFnOrClass(fnOrClass, annotations);
- this.providers.set(token, provider);
- },
- _hasProviderFor: function(token) {
- if (this.providers.has(token)) {
- return true;
- }
- if (this.parent) {
- return this.parent._hasProviderFor(token);
- }
- return false;
- },
- get: function(token) {
- var resolving = arguments[1] !== (void 0) ? arguments[1] : [];
- var wantPromise = arguments[2] !== (void 0) ? arguments[2] : false;
- var wantLazy = arguments[3] !== (void 0) ? arguments[3] : false;
- var $__0 = this;
- var resolvingMsg = '';
- var provider;
- var instance;
- var injector = this;
- if (token === null || token === undefined) {
- resolvingMsg = constructResolvingMessage(resolving, token);
- throw new Error(("Invalid token \"" + token + "\" requested!" + resolvingMsg));
- }
- if (token === Injector) {
- if (wantPromise) {
- return Promise.resolve(this);
- }
- return this;
- }
- if (wantLazy) {
- return function createLazyInstance() {
- var lazyInjector = injector;
- if (arguments.length) {
- var locals = [];
- var args = arguments;
- for (var i = 0; i < args.length; i += 2) {
- locals.push((function(ii) {
- var fn = function createLocalInstance() {
- return args[ii + 1];
- };
- annotate(fn, new InjectAnnotation());
- annotate(fn, new ProvideAnnotation(args[ii]));
- return fn;
- })(i));
- }
- lazyInjector = injector.createChild(locals);
- }
- return lazyInjector.get(token, resolving, wantPromise, false);
- };
- }
- if (this.cache.has(token)) {
- instance = this.cache.get(token);
- provider = this.providers.get(token);
- if (provider.isPromise && !wantPromise) {
- resolvingMsg = constructResolvingMessage(resolving, token);
- throw new Error(("Cannot instantiate " + toString(token) + " synchronously. It is provided as a promise!" + resolvingMsg));
- }
- if (!provider.isPromise && wantPromise) {
- return Promise.resolve(instance);
- }
- return instance;
- }
- provider = this.providers.get(token);
- if (!provider && !this._hasProviderFor(token)) {
- if (isFunction(token) && (hasAnnotation(token, InjectAnnotation)) || hasParameterAnnotation(token, InjectAnnotation)) {
- provider = createProviderFromFnOrClass(token, readAnnotations(token));
- this.providers.set(token, provider);
- } else if (isFunction(token) || isObject(token)) {
- provider = createProviderFromValue(token);
- this.providers.set(token, provider);
- }
- }
- if (!provider) {
- if (!this.parent) {
- resolvingMsg = constructResolvingMessage(resolving, token);
- throw new Error(("No provider for " + toString(token) + "!" + resolvingMsg));
- }
- return this.parent.get(token, resolving, wantPromise, wantLazy);
- }
- if (resolving.indexOf(token) !== -1) {
- resolvingMsg = constructResolvingMessage(resolving, token);
- throw new Error(("Cannot instantiate cyclic dependency!" + resolvingMsg));
- }
- resolving.push(token);
- var delayingInstantiation = wantPromise && provider.params.some((function(param) {
- return !param.isPromise;
- }));
- var args = provider.params.map((function(param) {
- if (delayingInstantiation) {
- return $__0.get(param.token, resolving, true, param.isLazy);
- }
- return $__0.get(param.token, resolving, param.isPromise, param.isLazy);
- }));
- if (delayingInstantiation) {
- var delayedResolving = resolving.slice();
- resolving.pop();
- return Promise.all(args).then(function(args) {
- try {
- instance = provider.create(args);
- } catch (e) {
- resolvingMsg = constructResolvingMessage(delayedResolving);
- var originalMsg = 'ORIGINAL ERROR: ' + e.message;
- e.message = ("Error during instantiation of " + toString(token) + "!" + resolvingMsg + "\n" + originalMsg);
- throw e;
- }
- if (!hasAnnotation(provider.provider, TransientScopeAnnotation)) {
- injector.cache.set(token, instance);
- }
- return instance;
- });
- }
- try {
- instance = provider.create(args);
- } catch (e) {
- resolvingMsg = constructResolvingMessage(resolving);
- var originalMsg = 'ORIGINAL ERROR: ' + e.message;
- e.message = ("Error during instantiation of " + toString(token) + "!" + resolvingMsg + "\n" + originalMsg);
- throw e;
- }
- if (!hasAnnotation(provider.provider, TransientScopeAnnotation)) {
- this.cache.set(token, instance);
- }
- if (!wantPromise && provider.isPromise) {
- resolvingMsg = constructResolvingMessage(resolving);
- throw new Error(("Cannot instantiate " + toString(token) + " synchronously. It is provided as a promise!" + resolvingMsg));
- }
- if (wantPromise && !provider.isPromise) {
- instance = Promise.resolve(instance);
- }
- resolving.pop();
- return instance;
- },
- getPromise: function(token) {
- return this.get(token, [], true);
- },
- createChild: function() {
- var modules = arguments[0] !== (void 0) ? arguments[0] : [];
- var forceNewInstancesOf = arguments[1] !== (void 0) ? arguments[1] : [];
- var forcedProviders = new Map();
- for (var $__2 = forceNewInstancesOf[$traceurRuntime.toProperty(Symbol.iterator)](),
- $__3 = void 0; !($__3 = $__2.next()).done; ) {
- var annotation = $__3.value;
- {
- this._collectProvidersWithAnnotation(annotation, forcedProviders);
- }
- }
- return new Injector(modules, this, forcedProviders);
- }
- }, {});
- }());
- $__export("Injector", Injector);
- }
- };
- });
- System.register("jiff/di/decorators", ["./annotations"], function($__export) {
- "use strict";
- var __moduleName = "jiff/di/decorators";
- var di,
- Inject,
- Provide;
- return {
- setters: [function($__m) {
- di = $__m;
- }],
- execute: function() {
- Inject = (function() {
- for (var dependencies = [],
- $__0 = 0; $__0 < arguments.length; $__0++)
- dependencies[$__0] = arguments[$__0];
- return (function(classDef) {
- di.annotate(classDef, new (Function.prototype.bind.apply(di.Inject, $traceurRuntime.spread([null], dependencies)))());
- });
- });
- Provide = (function(targetClassDef) {
- return (function(classDef) {
- di.annotate(classDef, new di.Provide(targetClassDef));
- });
- });
- $__export("Provide", Provide), $__export("Inject", Inject);
- }
- };
- });
- System.register("jiff/di", ["./di/decorators", "./di/injector"], function($__export) {
- "use strict";
- var __moduleName = "jiff/di";
- var $__exportNames = {};
- var $__exportNames = {};
- return {
- setters: [function($__m) {
- Object.keys($__m).forEach(function(p) {
- if (!$__exportNames[p])
- $__export(p, $__m[p]);
- });
- }, function($__m) {
- Object.keys($__m).forEach(function(p) {
- if (!$__exportNames[p])
- $__export(p, $__m[p]);
- });
- }],
- execute: function() {}
- };
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement