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C,CAYA,SAAS,gBAAgB,EAAW,EAAa,EAAiB,GAC9D,IAAI,EAAS,KAAK,UAAU,GAC5B,MAAM,EAAQ,UAEd,IAAI,EAAgB,iBAAiB,KAAK,KAAM,GAEhD,OAAO,eAAe,EAAU,UAAW,EAAgB,CACvD,MAAO,EACP,YAAY,EACZ,cAAc,EACd,UAAU,IAGd,qBAAqB,EAAW,EAAQ,EAC5C,CAUA,SAAS,iBAAiB,GACtB,OAAO,WACH,IAAI,EAAgB,kBAAkB,KAAK,KAAM,EAAO,MACxD,OAAO,EAAO,MAAM,GAAiB,KAAM,UAC/C,CACJ,CAWA,SAAS,kBAAkB,GACvB,OAAI,gBAAgB,MAAc,KAGpB,KAFK,KAAK,YAAY,yBACL,GAKnC,CAWA,SAAS,eAAe,EAAW,EAAa,GAG5C,GAFA,MAAM,EAAc,MAAM,SAAS,MAAM,MAAM,CAAC,QAAS,MAAM,WAAW,WAEtE,MAAM,QAAQ,GACd,EAAa,SAAQ,SAAS,GAC1B,gBAAgB,KAAK,KAAM,EAAW,EAAa,EAAY,EACnE,GAAG,WAEH,IAAK,IAAI,KAAkB,EACvB,GAAI,EAAa,eAAe,GAAiB,CAC7C,IAAI,EAAkB,EAAa,GACnC,gBAAgB,KAAK,KAAM,EAAW,EAAa,EAAiB,EACxE,CAGZ,CA1NA,OAAO,QAAU,MAwCjB,MAAM,UAAU,mBAAqB,mBACrC,MAAM,UAAU,oBAAsB,oBAStC,MAAM,QAAU","file":"/npm/ml-mixin@0.1.0/lib/mixin.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/ml-mixin@0.1.0/lib/mixin.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\n\nvar _ = require('protojs')\n    , check = require('ml-check')\n    , Match = check.Match;\n\nvar INSTANCE_PROPERTIES_MAP = '___mixin_instances';\n\n\nmodule.exports = Mixin;\n\n/**\n * `milo.classes.Mixin` - an abstract Mixin class.\n * Can be subclassed using protojs for example:\n * ```\n * var MyMixin = _.createSubclass(milo.classes.Mixin, 'MyMixin');\n * ```\n *\n * Mixin pattern is also used, but Mixin in milo is implemented as a separate object that is stored on the property of the host object and can create proxy methods on the host object if required.\n * Classes [Messenger](../messenger/index.js.html) and [MessageSource](../messenger/m_source.js.html) are subclasses of Mixin abstract class. `this` in proxy methods refers to Mixin instance, the reference to the host object is `this._hostObject`.\n *\n * @param {Object} hostObject Optional object where a Mixin instance will be stored on. It is used to proxy methods and also to find the reference when it is needed for host object implementation.\n * @param {Object} proxyMethods Optional map of proxy method names as keys and Mixin methods names as values, so proxied methods can be renamed to avoid name-space conflicts if two different Mixin instances with the same method names are put on the object\n * @param {List} arguments all constructor arguments will be passed to init method of Mixin subclass together with hostObject and proxyMethods\n * @return {Mixin}\n */\nfunction Mixin(hostObject, proxyMethods) { // , other args - passed to init method\n    check(hostObject, Match.Optional(Match.OneOf(Object, Function)));\n\n    // store hostObject\n    Object.defineProperty(this, '_hostObject', { value: hostObject });\n\n    // proxy methods to hostObject\n    if (proxyMethods)\n        this._createProxyMethods(proxyMethods);\n\n    // calling init if it is defined in the class\n    if (this.init)\n        this.init.apply(this, arguments);\n}\n\n\n/**\n * ####Mixin instance methods####\n * These methods are called by constructor, they are not to be called from subclasses.\n *\n * - [_createProxyMethod](#_createProxyMethod)\n * - [_createProxyMethods](#_createProxyMethods)\n */\nMixin.prototype._createProxyMethod = _createProxyMethod;\nMixin.prototype._createProxyMethods = _createProxyMethods;\n\n\n/**\n * ####Mixin class methods####\n * These method should be called in host class declaration.\n *\n * - [useWith](#Mixin$$useWith)\n */\nMixin.useWith = Mixin$$useWith;\n\n\n/**\n * Creates a proxied method of Mixin subclass on host object.\n *\n * @param {String} mixinMethodName name of method in Mixin subclass\n * @param {String} proxyMethodName name of created proxy method on host object\n * @param {Object} hostObject Optional reference to the host object; if not specified the host object passed to constructor wil be used. It allows to use the same instance of Mixin on two host objects.\n */\nfunction _createProxyMethod(proxyMethodName, mixinMethodName, hostObject) {\n    hostObject = hostObject || this._hostObject;\n\n    // Mixin class does not allow shadowing methods that exist on the host object\n    if (hostObject[proxyMethodName])\n        throw new Error('method ' + proxyMethodName +\n                        ' already defined in host object');\n\n    var method = this[mixinMethodName]\n    check(method, Function);\n\n    // Bind proxied Mixin's method to Mixin instance\n    var boundMethod = method.bind(this);\n\n    Object.defineProperty(hostObject, proxyMethodName, {\n        value: boundMethod,\n        enumerable: false,\n        configurable: false,\n        writable: true\n    });\n}\n\n\n/**\n * Creates proxied methods of Mixin subclass on host object.\n *\n * @param {Hash[String]|Array[String]} proxyMethods map of names of methods, key - proxy method name, value - mixin method name. Can be array.\n * @param {Object} hostObject an optional reference to the host object; if not specified the host object passed to constructor wil be used. It allows to use the same instance of Mixin on two host objects.\n */\nfunction _createProxyMethods(proxyMethods, hostObject) {\n    check(proxyMethods, Match.Optional(Match.OneOf([String], Match.ObjectHash(String))));\n\n    // creating and binding proxy methods on the host object\n    if (Array.isArray(proxyMethods))\n        proxyMethods.forEach(function(methodName) {\n            // method called this way to allow using _createProxyMethods with objects\n            // that are not inheriting from Mixin\n            _createProxyMethod.call(this, methodName, methodName, hostObject);\n        }, this);\n    else\n        for (var proxyMethodName in proxyMethods) {\n            // method called this way to allow using _createProxyMethods with objects\n            // that are not inheriting from Mixin\n            if (proxyMethods.hasOwnProperty(proxyMethodName)) {\n                var mixinMethodName = proxyMethods[proxyMethodName];\n                _createProxyMethod.call(this, proxyMethodName, mixinMethodName, hostObject);\n            }\n        }\n}\n\n\n/**\n * Sets mixin instance property name on the host class\n * Can be called only once\n *\n * @private\n * @param {Function} this Mixin subclass (not instance)\n * @param {Function} hostClass\n * @param {String} instanceKey\n */\nfunction Mixin_setInstanceKey(hostClass, method, instanceKey) {\n    check(hostClass, Function);\n    check(instanceKey, Match.IdentifierString);\n\n    var prop = INSTANCE_PROPERTIES_MAP\n        , instanceKeys = hostClass[prop] = hostClass[prop] || {};\n\n    if (instanceKeys[method.name])\n        throw new Error('Mixin: instance property for method with name '\n            + method.name + ' is already set');\n\n    instanceKeys[method.name] = instanceKey;\n}\n\n\n/**\n * Adds method of Mixin subclass to host class prototype.\n *\n * @private\n * @param {Function} this Mixin subclass (not instance)\n * @param {String} mixinMethodName name of method in Mixin subclass\n * @param {String} hostMethodName (optional) name of created proxy method on host object, same if not specified\n * @param {Object} hostObject object class, must be specified as the last parameter (2nd or 3rd)\n */\nfunction Mixin_addMethod(hostClass, instanceKey, mixinMethodName, hostMethodName) {\n    var method = this.prototype[mixinMethodName];\n    check(method, Function);\n\n    var wrappedMethod = _wrapMixinMethod.call(this, method);\n\n    Object.defineProperty(hostClass.prototype, hostMethodName, {\n        value: wrappedMethod,\n        enumerable: false,\n        configurable: false,\n        writable: true\n    });\n\n    Mixin_setInstanceKey(hostClass, method, instanceKey)\n}\n\n\n/**\n * Returns method that will be exposed on the host class prototype\n *\n * @private\n * @param {Function} this Mixin subclass (not instance)\n * @return {Function}\n */\nfunction _wrapMixinMethod(method) {\n    return function() { // ,... arguments\n        var mixinInstance = _getMixinInstance.call(this, method.name);\n        return method.apply(mixinInstance || this, arguments);\n    }\n}\n\n\n/**\n * Returns the reference to the instance of mixin subclass.\n * This method is used when methods are exposed on the host class prototype (using addMehtods) rather than on host instance.\n * Subclasses should not use this methods - whenever subclass method is exposed on the prototype it will be wrapped to set correct context for the subclass method.\n *\n * @private\n * @return {Object}\n */\nfunction _getMixinInstance(methodName) {\n    if (this instanceof Mixin) return this;\n    var instanceKeys = this.constructor[INSTANCE_PROPERTIES_MAP]\n        , mixinProp = instanceKeys[methodName]\n        , mixin = this[mixinProp];\n    return mixin;\n    // if (!mixin) throw new Error('Mixin ' + mixinProp + ' does not exist');\n    // return mixin;\n}\n\n\n/**\n * Adds methods of Mixin subclass to host class prototype.\n *\n * @param {Function} this Mixin subclass (not instance)\n * @param {Object} hostClass host object class; must be specified.\n * @param {String} instanceKey the name of the property the host class instance will store mixin instance on\n * @param {Hash[String]|Array[String]} mixinMethods map of names of methods, key - host method name, value - mixin method name. Can be array.\n */\nfunction Mixin$$useWith(hostClass, instanceKey, mixinMethods) {\n    check(mixinMethods, Match.Optional(Match.OneOf([String], Match.ObjectHash(String))));\n\n    if (Array.isArray(mixinMethods)) {\n        mixinMethods.forEach(function(methodName) {\n            Mixin_addMethod.call(this, hostClass, instanceKey, methodName, methodName);\n        }, this);\n    } else {\n        for (var hostMethodName in mixinMethods) {\n            if (mixinMethods.hasOwnProperty(hostMethodName)) {\n                var mixinMethodName = mixinMethods[hostMethodName];\n                Mixin_addMethod.call(this, hostClass, instanceKey, mixinMethodName, hostMethodName);\n            }\n        }\n    }\n}\n"]}