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SAAQ,AAAC,CAAC,KAAI,KAAK,CAAC,CAAG;AACzB,oBAAY,OAAO,AAAC,CAAC,KAAI,KAAK,CAAG,CAAA,KAAI,OAAO,aAAa,CAAC,CAAC;MAC7D,KAAO;AACL,YAAI,KAAK,EAAI,CAAA,aAAY,OAAO,AAAC,CAAC,KAAI,OAAO,aAAa,CAAC,CAAC;MAC9D;AAAA,IACF;AAAA,AACA,SAAO,OAAK,CAAC;EACf;CAhHmF;AAArF,KAAK,eAAe,AAAC,oBACb,EAAC,GAAE,CAAG,UAAS,AAAD,CAAG;AAAC,cAqCzB,SAAO,AAAC,CAAC;AACR,aAAO,CAAG,YAAU;AACpB,eAAS,CAAG,EACV,iBAAgB,CAAG,oBAAkB,CACvC;AAAA,IACF,CAAC,EA1CgD;EAAC,CAAC,CAAC,CAAC;AADrD,KAAK,eAAe,AAAC,mBACb,EAAC,GAAE,CAAG,UAAS,AAAD,CAAG;AAAC,YA6CE,aAAY,GA7CS;EAAC,CAAC,CAAC,CAAC;AADrD,AAAI,EAAA,kBAmHJ,SAAM,gBAAc,CAGN,MAAK,CAAG,CAAA,IAAG,CAAG;AACxB,KAAG,OAAO,EAAI,OAAK,CAAC;AACpB,KAAG,KAAK,EAAI,KAAG,CAAC;AAClB,AAzHsC,CAAA;AAAxC,AAAC,eAAc,YAAY,CAAC,AAAC,yBAAwD;AA2HrF","file":"angular2/src/directives/for.js","sourcesContent":["import {Viewport} from 'angular2/src/core/annotations/annotations';\nimport {ViewContainer} from 'angular2/src/core/compiler/view_container';\nimport {AppView} from 'angular2/src/core/compiler/view';\nimport {isPresent, isBlank} from 'angular2/src/facade/lang';\nimport {ListWrapper} from 'angular2/src/facade/collection';\n\n/**\n * The `For` directive instantiates a template once per item from an iterable. The context for each\n * instantiated template inherits from the outer context with the given loop variable set to the\n * current item from the iterable.\n *\n * It is possible to alias the `index` to a local variable that will be set to the current loop\n * iteration in the template context.\n *\n * When the contents of the iterator changes, `For` makes the corresponding changes to the DOM:\n *\n * * When an item is added, a new instance of the template is added to the DOM.\n * * When an item is removed, its template instance is removed from the DOM.\n * * When items are reordered, their respective templates are reordered in the DOM.\n *\n * # Example\n *\n * ```\n * <ul>\n * <li *for=\"#error in errors; #i = index\">\n * Error {{i}} of {{errors.length}}: {{error.message}}\n * </li>\n * </ul>\n * ```\n *\n * # Syntax\n *\n * - `<li *for=\"#item of items; #i = index\">...</li>`\n * - `<li template=\"for #item of items; #i=index\">...</li>`\n * - `<template [for]=\"#item\" [of]=\"items\" #i=\"index\"><li>...</li></template>`\n *\n * @exportedAs angular2/directives\n */\n@Viewport({\n selector: '[for][of]',\n properties: {\n 'iterableChanges': 'of | iterableDiff'\n }\n})\nexport class For {\n viewContainer: ViewContainer;\n constructor(viewContainer:ViewContainer) {\n this.viewContainer = viewContainer;\n }\n\n set iterableChanges(changes) {\n if (isBlank(changes)) {\n this.viewContainer.clear();\n return;\n }\n\n // TODO(rado): check if change detection can produce a change record that is\n // easier to consume than current.\n var recordViewTuples = [];\n changes.forEachRemovedItem(\n (removedRecord) => ListWrapper.push(recordViewTuples, new RecordViewTuple(removedRecord, null))\n );\n\n changes.forEachMovedItem(\n (movedRecord) => ListWrapper.push(recordViewTuples, new RecordViewTuple(movedRecord, null))\n );\n\n var insertTuples = For.bulkRemove(recordViewTuples, this.viewContainer);\n\n changes.forEachAddedItem(\n (addedRecord) => ListWrapper.push(insertTuples, new RecordViewTuple(addedRecord, null))\n );\n\n For.bulkInsert(insertTuples, this.viewContainer);\n\n for (var i = 0; i < insertTuples.length; i++) {\n this.perViewChange(insertTuples[i].view, insertTuples[i].record);\n }\n }\n\n perViewChange(view, record) {\n view.setLocal('\\$implicit', record.item);\n view.setLocal('index', record.currentIndex);\n }\n\n static bulkRemove(tuples, viewContainer) {\n tuples.sort((a, b) => a.record.previousIndex - b.record.previousIndex);\n var movedTuples = [];\n for (var i = tuples.length - 1; i >= 0; i--) {\n var tuple = tuples[i];\n // separate moved views from removed views.\n if (isPresent(tuple.record.currentIndex)) {\n tuple.view = viewContainer.detach(tuple.record.previousIndex);\n ListWrapper.push(movedTuples, tuple);\n } else {\n viewContainer.remove(tuple.record.previousIndex);\n }\n }\n return movedTuples;\n }\n\n static bulkInsert(tuples, viewContainer) {\n tuples.sort((a, b) => a.record.currentIndex - b.record.currentIndex);\n for (var i = 0; i < tuples.length; i++) {\n var tuple = tuples[i];\n if (isPresent(tuple.view)) {\n viewContainer.insert(tuple.view, tuple.record.currentIndex);\n } else {\n tuple.view = viewContainer.create(tuple.record.currentIndex);\n }\n }\n return tuples;\n }\n}\n\nclass RecordViewTuple {\n view: AppView;\n record: any;\n constructor(record, view) {\n this.record = record;\n this.view = view;\n }\n}\n"]}