2016-01-15 00:01:56 +01:00

1 line
36 KiB
Plaintext

{"version":3,"sources":["../yjs/node_modules/browser-pack/_prelude.js","src/Map.js","y-map.js"],"names":["e","t","n","r","s","o","u","a","require","i","f","Error","code","l","exports","call","length",1,"module","_classCallCheck","instance","Constructor","TypeError","extend","Y","YMap","os","model","contents","opContents","_this","this","_model","id","map","utils","copyObject","eventHandler","EventHandler","ops","userEvents","oldValue","op","key","struct","parentSub","prevType","Promise","resolve","requestTransaction","regeneratorRuntime","mark","_callee","type","wrap","_context","prev","next","delegateYield","getType","t0","stop","left","opContent","deleted","content","insertEvent","undefined","name","object","push","compareIds","target","deleteEvent","callEventListeners","_createClass","value","_this2","oid","_callee2","_context2","right","del","modDel","awaitAndPrematurelyCall","_callee3","_context3","applyCreatedOperations","awaitedDeletes","_this3","insert","origin","parent","CustomType","_callee4","_context4","createType","store","getNextOpId","_callee5","_context5","awaitedInserts","addEventListener","removeEventListener","path","observeProperty","events","event","propertyName","property","self","get","then","observe","unobserve","deleteChildObservers","resetObserverPath","promise","set","Map","observePath","slice","_deleteChildObservers","observer","_changed","transaction","_context6","getOperation","receivedOp","class","initType","YMapInitializer","_context7","keys","t1","done","t2","abrupt","defineProperties","props","descriptor","enumerable","configurable","writable","Object","defineProperty","protoProps","staticProps","prototype"],"mappings":"CAAA,QAAAA,GAAAC,EAAAC,EAAAC,GAAA,QAAAC,GAAAC,EAAAC,GAAA,IAAAJ,EAAAG,GAAA,CAAA,IAAAJ,EAAAI,GAAA,CAAA,GAAAE,GAAA,kBAAAC,UAAAA,OAAA,KAAAF,GAAAC,EAAA,MAAAA,GAAAF,GAAA,EAAA,IAAAI,EAAA,MAAAA,GAAAJ,GAAA,EAAA,IAAAK,GAAA,GAAAC,OAAA,uBAAAN,EAAA,IAAA,MAAAK,GAAAE,KAAA,mBAAAF,EAAA,GAAAG,GAAAX,EAAAG,IAAAS,WAAAb,GAAAI,GAAA,GAAAU,KAAAF,EAAAC,QAAA,SAAAd,GAAA,GAAAE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9RxC,GAAI4C,GAAe,WAAc,QAAS+D,GAAiBlE,EAAQmE,GAAS,IAAK,GAAIlI,GAAI,EAAGA,EAAIkI,EAAM3H,OAAQP,IAAK,CAAE,GAAImI,GAAaD,EAAMlI,EAAImI,GAAWC,WAAaD,EAAWC,aAAc,EAAOD,EAAWE,cAAe,EAAU,SAAWF,KAAYA,EAAWG,UAAW,GAAMC,OAAOC,eAAezE,EAAQoE,EAAWjG,IAAKiG,IAAiB,MAAO,UAAUvH,EAAa6H,EAAYC,GAAiJ,MAA9HD,IAAYR,EAAiBrH,EAAY+H,UAAWF,GAAiBC,GAAaT,EAAiBrH,EAAa8H,GAAqB9H,KD+ShiBH,GAAOJ,QAAUS,EACA,mBAANC,IACTD,EAAOC,aCqKE","file":"y-map.js","sourcesContent":["(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})","/* global Y */\r\n'use strict'\r\n\r\nfunction extend (Y /* :any */) {\r\n class YMap {\r\n /* ::\r\n _model: Id;\r\n os: Y.AbstractDatabase;\r\n map: Object;\r\n contents: any;\r\n opContents: Object;\r\n eventHandler: Function;\r\n */\r\n constructor (os, model, contents, opContents) {\r\n this._model = model.id\r\n this.os = os\r\n this.map = Y.utils.copyObject(model.map)\r\n this.contents = contents\r\n this.opContents = opContents\r\n this.eventHandler = new Y.utils.EventHandler(ops => {\r\n var userEvents = []\r\n for (var i in ops) {\r\n var op = ops[i]\r\n var oldValue\r\n // key is the name to use to access (op)content\r\n var key = op.struct === 'Delete' ? op.key : op.parentSub\r\n\r\n // compute oldValue\r\n if (this.opContents[key] != null) {\r\n let prevType = this.opContents[key]\r\n oldValue = () => {// eslint-disable-line\r\n return new Promise((resolve) => {\r\n this.os.requestTransaction(function *() {// eslint-disable-line\r\n var type = yield* this.getType(prevType)\r\n resolve(type)\r\n })\r\n })\r\n }\r\n } else {\r\n oldValue = this.contents[key]\r\n }\r\n // compute op event\r\n if (op.struct === 'Insert') {\r\n if (op.left === null) {\r\n if (op.opContent != null) {\r\n delete this.contents[key]\r\n if (op.deleted) {\r\n delete this.opContents[key]\r\n } else {\r\n this.opContents[key] = op.opContent\r\n }\r\n } else {\r\n delete this.opContents[key]\r\n if (op.deleted) {\r\n delete this.contents[key]\r\n } else {\r\n this.contents[key] = op.content\r\n }\r\n }\r\n this.map[key] = op.id\r\n var insertEvent\r\n if (oldValue === undefined) {\r\n insertEvent = {\r\n name: key,\r\n object: this,\r\n type: 'add'\r\n }\r\n } else {\r\n insertEvent = {\r\n name: key,\r\n object: this,\r\n oldValue: oldValue,\r\n type: 'update'\r\n }\r\n }\r\n userEvents.push(insertEvent)\r\n }\r\n } else if (op.struct === 'Delete') {\r\n if (Y.utils.compareIds(this.map[key], op.target)) {\r\n delete this.opContents[key]\r\n delete this.contents[key]\r\n var deleteEvent = {\r\n name: key,\r\n object: this,\r\n oldValue: oldValue,\r\n type: 'delete'\r\n }\r\n userEvents.push(deleteEvent)\r\n }\r\n } else {\r\n throw new Error('Unexpected Operation!')\r\n }\r\n }\r\n if (userEvents.length > 0) {\r\n this.eventHandler.callEventListeners(userEvents)\r\n }\r\n })\r\n }\r\n get (key) {\r\n // return property.\r\n // if property does not exist, return null\r\n // if property is a type, return a promise\r\n if (key == null) {\r\n throw new Error('You must specify key!')\r\n }\r\n if (this.opContents[key] == null) {\r\n return this.contents[key]\r\n } else {\r\n return new Promise((resolve) => {\r\n var oid = this.opContents[key]\r\n this.os.requestTransaction(function *() {\r\n var type = yield* this.getType(oid)\r\n resolve(type)\r\n })\r\n })\r\n }\r\n }\r\n /*\r\n If there is a primitive (not a custom type), then return it.\r\n Returns all primitive values, if propertyName is specified!\r\n Note: modifying the return value could result in inconsistencies!\r\n -- so make sure to copy it first!\r\n */\r\n getPrimitive (key) {\r\n if (key == null) {\r\n return Y.utils.copyObject(this.contents)\r\n } else {\r\n return this.contents[key]\r\n }\r\n }\r\n delete (key) {\r\n var right = this.map[key]\r\n if (right != null) {\r\n var del = {\r\n target: right,\r\n struct: 'Delete'\r\n }\r\n var eventHandler = this.eventHandler\r\n var modDel = Y.utils.copyObject(del)\r\n modDel.key = key\r\n eventHandler.awaitAndPrematurelyCall([modDel])\r\n this.os.requestTransaction(function *() {\r\n yield* this.applyCreatedOperations([del])\r\n eventHandler.awaitedDeletes(1)\r\n })\r\n }\r\n }\r\n set (key, value) {\r\n // set property.\r\n // if property is a type, return a promise\r\n // if not, apply immediately on this type an call event\r\n\r\n var right = this.map[key] || null\r\n var insert /* :any */ = {\r\n left: null,\r\n right: right,\r\n origin: null,\r\n parent: this._model,\r\n parentSub: key,\r\n struct: 'Insert'\r\n }\r\n return new Promise((resolve) => {\r\n if (value instanceof Y.utils.CustomType) {\r\n // construct a new type\r\n this.os.requestTransaction(function *() {\r\n var type = yield* this.createType(value)\r\n insert.opContent = type._model\r\n insert.id = this.store.getNextOpId()\r\n yield* this.applyCreatedOperations([insert])\r\n resolve(type)\r\n })\r\n } else {\r\n insert.content = value\r\n insert.id = this.os.getNextOpId()\r\n var eventHandler = this.eventHandler\r\n eventHandler.awaitAndPrematurelyCall([insert])\r\n this.os.requestTransaction(function *() {\r\n yield* this.applyCreatedOperations([insert])\r\n eventHandler.awaitedInserts(1)\r\n })\r\n resolve(value)\r\n }\r\n })\r\n }\r\n observe (f) {\r\n this.eventHandler.addEventListener(f)\r\n }\r\n unobserve (f) {\r\n this.eventHandler.removeEventListener(f)\r\n }\r\n /*\r\n Observe a path.\r\n\r\n E.g.\r\n ```\r\n o.set('textarea', Y.TextBind)\r\n o.observePath(['textarea'], function(t){\r\n // is called whenever textarea is replaced\r\n t.bind(textarea)\r\n })\r\n\r\n returns a Promise that contains a function that removes the observer from the path.\r\n */\r\n observePath (path, f) {\r\n var self = this\r\n function observeProperty (events) {\r\n // call f whenever path changes\r\n for (var i = 0; i < events.length; i++) {\r\n var event = events[i]\r\n if (event.name === propertyName) {\r\n // call this also for delete events!\r\n var property = self.get(propertyName)\r\n if (property instanceof Promise) {\r\n property.then(f)\r\n } else {\r\n f(property)\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (path.length < 1) {\r\n throw new Error('Path must contain at least one element!')\r\n } else if (path.length === 1) {\r\n var propertyName = path[0]\r\n var property = self.get(propertyName)\r\n if (property instanceof Promise) {\r\n property.then(f)\r\n } else {\r\n f(property)\r\n }\r\n this.observe(observeProperty)\r\n return Promise.resolve(function () {\r\n self.unobserve(f)\r\n })\r\n } else {\r\n var deleteChildObservers\r\n var resetObserverPath = function () {\r\n var promise = self.get(path[0])\r\n if (!promise instanceof Promise) {\r\n // its either not defined or a primitive value\r\n promise = self.set(path[0], Y.Map)\r\n }\r\n return promise.then(function (map) {\r\n return map.observePath(path.slice(1), f)\r\n }).then(function (_deleteChildObservers) {\r\n // update deleteChildObservers\r\n deleteChildObservers = _deleteChildObservers\r\n return Promise.resolve() // Promise does not return anything\r\n })\r\n }\r\n var observer = function (events) {\r\n for (var e in events) {\r\n var event = events[e]\r\n if (event.name === path[0]) {\r\n if (deleteChildObservers != null) {\r\n deleteChildObservers()\r\n }\r\n if (event.type === 'add' || event.type === 'update') {\r\n resetObserverPath()\r\n }\r\n // TODO: what about the delete events?\r\n }\r\n }\r\n }\r\n self.observe(observer)\r\n return resetObserverPath().then(\r\n // this promise contains a function that deletes all the child observers\r\n // and how to unobserve the observe from this object\r\n new Promise.resolve(function () { // eslint-disable-line\r\n if (deleteChildObservers != null) {\r\n deleteChildObservers()\r\n }\r\n self.unobserve(observer)\r\n })\r\n )\r\n }\r\n }\r\n * _changed (transaction, op) {\r\n if (op.struct === 'Delete') {\r\n var target = yield* transaction.getOperation(op.target)\r\n op.key = target.parentSub\r\n }\r\n this.eventHandler.receivedOp(op)\r\n }\r\n }\r\n Y.extend('Map', new Y.utils.CustomType({\r\n name: 'Map',\r\n class: YMap,\r\n struct: 'Map',\r\n initType: function * YMapInitializer (os, model) {\r\n var contents = {}\r\n var opContents = {}\r\n var map = model.map\r\n for (var name in map) {\r\n var op = yield* this.getOperation(map[name])\r\n if (op.opContent != null) {\r\n opContents[name] = op.opContent\r\n } else {\r\n contents[name] = op.content\r\n }\r\n }\r\n return new YMap(os, model, contents, opContents)\r\n }\r\n }))\r\n}\r\n\r\nmodule.exports = extend\r\nif (typeof Y !== 'undefined') {\r\n extend(Y)\r\n}\r\n","(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){\n/* global Y */\n'use strict';\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction extend(Y /* :any */) {\n var YMap = function () {\n /* ::\r\n _model: Id;\r\n os: Y.AbstractDatabase;\r\n map: Object;\r\n contents: any;\r\n opContents: Object;\r\n eventHandler: Function;\r\n */\n\n function YMap(os, model, contents, opContents) {\n var _this = this;\n\n _classCallCheck(this, YMap);\n\n this._model = model.id;\n this.os = os;\n this.map = Y.utils.copyObject(model.map);\n this.contents = contents;\n this.opContents = opContents;\n this.eventHandler = new Y.utils.EventHandler(function (ops) {\n var userEvents = [];\n for (var i in ops) {\n var op = ops[i];\n var oldValue;\n // key is the name to use to access (op)content\n var key = op.struct === 'Delete' ? op.key : op.parentSub;\n\n // compute oldValue\n if (_this.opContents[key] != null) {\n (function () {\n var prevType = _this.opContents[key];\n oldValue = function oldValue() {\n // eslint-disable-line\n return new Promise(function (resolve) {\n _this.os.requestTransaction(regeneratorRuntime.mark(function _callee() {\n var type;\n return regeneratorRuntime.wrap(function _callee$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n return _context.delegateYield(this.getType(prevType), 't0', 1);\n\n case 1:\n type = _context.t0;\n\n resolve(type);\n\n case 3:\n case 'end':\n return _context.stop();\n }\n }\n }, _callee, this);\n }));\n });\n };\n })();\n } else {\n oldValue = _this.contents[key];\n }\n // compute op event\n if (op.struct === 'Insert') {\n if (op.left === null) {\n if (op.opContent != null) {\n delete _this.contents[key];\n if (op.deleted) {\n delete _this.opContents[key];\n } else {\n _this.opContents[key] = op.opContent;\n }\n } else {\n delete _this.opContents[key];\n if (op.deleted) {\n delete _this.contents[key];\n } else {\n _this.contents[key] = op.content;\n }\n }\n _this.map[key] = op.id;\n var insertEvent;\n if (oldValue === undefined) {\n insertEvent = {\n name: key,\n object: _this,\n type: 'add'\n };\n } else {\n insertEvent = {\n name: key,\n object: _this,\n oldValue: oldValue,\n type: 'update'\n };\n }\n userEvents.push(insertEvent);\n }\n } else if (op.struct === 'Delete') {\n if (Y.utils.compareIds(_this.map[key], op.target)) {\n delete _this.opContents[key];\n delete _this.contents[key];\n var deleteEvent = {\n name: key,\n object: _this,\n oldValue: oldValue,\n type: 'delete'\n };\n userEvents.push(deleteEvent);\n }\n } else {\n throw new Error('Unexpected Operation!');\n }\n }\n if (userEvents.length > 0) {\n _this.eventHandler.callEventListeners(userEvents);\n }\n });\n }\n\n _createClass(YMap, [{\n key: 'get',\n value: function get(key) {\n var _this2 = this;\n\n // return property.\n // if property does not exist, return null\n // if property is a type, return a promise\n if (key == null) {\n throw new Error('You must specify key!');\n }\n if (this.opContents[key] == null) {\n return this.contents[key];\n } else {\n return new Promise(function (resolve) {\n var oid = _this2.opContents[key];\n _this2.os.requestTransaction(regeneratorRuntime.mark(function _callee2() {\n var type;\n return regeneratorRuntime.wrap(function _callee2$(_context2) {\n while (1) {\n switch (_context2.prev = _context2.next) {\n case 0:\n return _context2.delegateYield(this.getType(oid), 't0', 1);\n\n case 1:\n type = _context2.t0;\n\n resolve(type);\n\n case 3:\n case 'end':\n return _context2.stop();\n }\n }\n }, _callee2, this);\n }));\n });\n }\n }\n /*\r\n If there is a primitive (not a custom type), then return it.\r\n Returns all primitive values, if propertyName is specified!\r\n Note: modifying the return value could result in inconsistencies!\r\n -- so make sure to copy it first!\r\n */\n\n }, {\n key: 'getPrimitive',\n value: function getPrimitive(key) {\n if (key == null) {\n return Y.utils.copyObject(this.contents);\n } else {\n return this.contents[key];\n }\n }\n }, {\n key: 'delete',\n value: function _delete(key) {\n var right = this.map[key];\n if (right != null) {\n var del = {\n target: right,\n struct: 'Delete'\n };\n var eventHandler = this.eventHandler;\n var modDel = Y.utils.copyObject(del);\n modDel.key = key;\n eventHandler.awaitAndPrematurelyCall([modDel]);\n this.os.requestTransaction(regeneratorRuntime.mark(function _callee3() {\n return regeneratorRuntime.wrap(function _callee3$(_context3) {\n while (1) {\n switch (_context3.prev = _context3.next) {\n case 0:\n return _context3.delegateYield(this.applyCreatedOperations([del]), 't0', 1);\n\n case 1:\n eventHandler.awaitedDeletes(1);\n\n case 2:\n case 'end':\n return _context3.stop();\n }\n }\n }, _callee3, this);\n }));\n }\n }\n }, {\n key: 'set',\n value: function set(key, value) {\n var _this3 = this;\n\n // set property.\n // if property is a type, return a promise\n // if not, apply immediately on this type an call event\n\n var right = this.map[key] || null;\n var insert /* :any */ = {\n left: null,\n right: right,\n origin: null,\n parent: this._model,\n parentSub: key,\n struct: 'Insert'\n };\n return new Promise(function (resolve) {\n if (value instanceof Y.utils.CustomType) {\n // construct a new type\n _this3.os.requestTransaction(regeneratorRuntime.mark(function _callee4() {\n var type;\n return regeneratorRuntime.wrap(function _callee4$(_context4) {\n while (1) {\n switch (_context4.prev = _context4.next) {\n case 0:\n return _context4.delegateYield(this.createType(value), 't0', 1);\n\n case 1:\n type = _context4.t0;\n\n insert.opContent = type._model;\n insert.id = this.store.getNextOpId();\n return _context4.delegateYield(this.applyCreatedOperations([insert]), 't1', 5);\n\n case 5:\n resolve(type);\n\n case 6:\n case 'end':\n return _context4.stop();\n }\n }\n }, _callee4, this);\n }));\n } else {\n insert.content = value;\n insert.id = _this3.os.getNextOpId();\n var eventHandler = _this3.eventHandler;\n eventHandler.awaitAndPrematurelyCall([insert]);\n _this3.os.requestTransaction(regeneratorRuntime.mark(function _callee5() {\n return regeneratorRuntime.wrap(function _callee5$(_context5) {\n while (1) {\n switch (_context5.prev = _context5.next) {\n case 0:\n return _context5.delegateYield(this.applyCreatedOperations([insert]), 't0', 1);\n\n case 1:\n eventHandler.awaitedInserts(1);\n\n case 2:\n case 'end':\n return _context5.stop();\n }\n }\n }, _callee5, this);\n }));\n resolve(value);\n }\n });\n }\n }, {\n key: 'observe',\n value: function observe(f) {\n this.eventHandler.addEventListener(f);\n }\n }, {\n key: 'unobserve',\n value: function unobserve(f) {\n this.eventHandler.removeEventListener(f);\n }\n /*\r\n Observe a path.\r\n E.g.\r\n ```\r\n o.set('textarea', Y.TextBind)\r\n o.observePath(['textarea'], function(t){\r\n // is called whenever textarea is replaced\r\n t.bind(textarea)\r\n })\r\n returns a Promise that contains a function that removes the observer from the path.\r\n */\n\n }, {\n key: 'observePath',\n value: function observePath(path, f) {\n var self = this;\n function observeProperty(events) {\n // call f whenever path changes\n for (var i = 0; i < events.length; i++) {\n var event = events[i];\n if (event.name === propertyName) {\n // call this also for delete events!\n var property = self.get(propertyName);\n if (property instanceof Promise) {\n property.then(f);\n } else {\n f(property);\n }\n }\n }\n }\n\n if (path.length < 1) {\n throw new Error('Path must contain at least one element!');\n } else if (path.length === 1) {\n var propertyName = path[0];\n var property = self.get(propertyName);\n if (property instanceof Promise) {\n property.then(f);\n } else {\n f(property);\n }\n this.observe(observeProperty);\n return Promise.resolve(function () {\n self.unobserve(f);\n });\n } else {\n var deleteChildObservers;\n var resetObserverPath = function resetObserverPath() {\n var promise = self.get(path[0]);\n if (!promise instanceof Promise) {\n // its either not defined or a primitive value\n promise = self.set(path[0], Y.Map);\n }\n return promise.then(function (map) {\n return map.observePath(path.slice(1), f);\n }).then(function (_deleteChildObservers) {\n // update deleteChildObservers\n deleteChildObservers = _deleteChildObservers;\n return Promise.resolve(); // Promise does not return anything\n });\n };\n var observer = function observer(events) {\n for (var e in events) {\n var event = events[e];\n if (event.name === path[0]) {\n if (deleteChildObservers != null) {\n deleteChildObservers();\n }\n if (event.type === 'add' || event.type === 'update') {\n resetObserverPath();\n }\n // TODO: what about the delete events?\n }\n }\n };\n self.observe(observer);\n return resetObserverPath().then(\n // this promise contains a function that deletes all the child observers\n // and how to unobserve the observe from this object\n new Promise.resolve(function () {\n // eslint-disable-line\n if (deleteChildObservers != null) {\n deleteChildObservers();\n }\n self.unobserve(observer);\n }));\n }\n }\n }, {\n key: '_changed',\n value: regeneratorRuntime.mark(function _changed(transaction, op) {\n var target;\n return regeneratorRuntime.wrap(function _changed$(_context6) {\n while (1) {\n switch (_context6.prev = _context6.next) {\n case 0:\n if (!(op.struct === 'Delete')) {\n _context6.next = 4;\n break;\n }\n\n return _context6.delegateYield(transaction.getOperation(op.target), 't0', 2);\n\n case 2:\n target = _context6.t0;\n\n op.key = target.parentSub;\n\n case 4:\n this.eventHandler.receivedOp(op);\n\n case 5:\n case 'end':\n return _context6.stop();\n }\n }\n }, _changed, this);\n })\n }]);\n\n return YMap;\n }();\n\n Y.extend('Map', new Y.utils.CustomType({\n name: 'Map',\n class: YMap,\n struct: 'Map',\n initType: regeneratorRuntime.mark(function YMapInitializer(os, model) {\n var contents, opContents, map, name, op;\n return regeneratorRuntime.wrap(function YMapInitializer$(_context7) {\n while (1) {\n switch (_context7.prev = _context7.next) {\n case 0:\n contents = {};\n opContents = {};\n map = model.map;\n _context7.t0 = regeneratorRuntime.keys(map);\n\n case 4:\n if ((_context7.t1 = _context7.t0()).done) {\n _context7.next = 11;\n break;\n }\n\n name = _context7.t1.value;\n return _context7.delegateYield(this.getOperation(map[name]), 't2', 7);\n\n case 7:\n op = _context7.t2;\n\n if (op.opContent != null) {\n opContents[name] = op.opContent;\n } else {\n contents[name] = op.content;\n }\n _context7.next = 4;\n break;\n\n case 11:\n return _context7.abrupt('return', new YMap(os, model, contents, opContents));\n\n case 12:\n case 'end':\n return _context7.stop();\n }\n }\n }, YMapInitializer, this);\n })\n }));\n}\n\nmodule.exports = extend;\nif (typeof Y !== 'undefined') {\n extend(Y);\n}\n\n},{}]},{},[1])\n\n"],"sourceRoot":"/source/"}