UNPKG

angular2

Version:

Angular 2 - a web framework for modern web apps

84 lines 3.9 kB
'use strict';var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc); } }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var lang_1 = require('angular2/src/facade/lang'); var exceptions_1 = require('angular2/src/facade/exceptions'); var collection_1 = require('angular2/src/facade/collection'); var di_1 = require('angular2/src/core/di'); /** * A repository of different iterable diffing strategies used by NgFor, NgClass, and others. */ var IterableDiffers = (function () { function IterableDiffers(factories) { this.factories = factories; } IterableDiffers.create = function (factories, parent) { if (lang_1.isPresent(parent)) { var copied = collection_1.ListWrapper.clone(parent.factories); factories = factories.concat(copied); return new IterableDiffers(factories); } else { return new IterableDiffers(factories); } }; /** * Takes an array of {@link IterableDifferFactory} and returns a provider used to extend the * inherited {@link IterableDiffers} instance with the provided factories and return a new * {@link IterableDiffers} instance. * * The following example shows how to extend an existing list of factories, * which will only be applied to the injector for this component and its children. * This step is all that's required to make a new {@link IterableDiffer} available. * * ### Example * * ``` * @Component({ * viewProviders: [ * IterableDiffers.extend([new ImmutableListDiffer()]) * ] * }) * ``` */ IterableDiffers.extend = function (factories) { return new di_1.Provider(IterableDiffers, { useFactory: function (parent) { if (lang_1.isBlank(parent)) { // Typically would occur when calling IterableDiffers.extend inside of dependencies passed // to // bootstrap(), which would override default pipes instead of extending them. throw new exceptions_1.BaseException('Cannot extend IterableDiffers without a parent injector'); } return IterableDiffers.create(factories, parent); }, // Dependency technically isn't optional, but we can provide a better error message this way. deps: [[IterableDiffers, new di_1.SkipSelfMetadata(), new di_1.OptionalMetadata()]] }); }; IterableDiffers.prototype.find = function (iterable) { var factory = this.factories.find(function (f) { return f.supports(iterable); }); if (lang_1.isPresent(factory)) { return factory; } else { throw new exceptions_1.BaseException("Cannot find a differ supporting object '" + iterable + "'"); } }; IterableDiffers = __decorate([ di_1.Injectable(), lang_1.CONST(), __metadata('design:paramtypes', [Array]) ], IterableDiffers); return IterableDiffers; })(); exports.IterableDiffers = IterableDiffers; //# sourceMappingURL=iterable_differs.js.map