/* mixin-js.js 0.1.5 (c) 2011, 2012 Kevin Malakoff - http://kmalakoff.github.com/mixin/ License: MIT (http://www.opensource.org/licenses/mit-license.php) */(function(){return function(e){return typeof define=="function"&&define.amd?define("mixin-js",e):e.call(this)}(function(){var e,t,n,r={}.hasOwnProperty,i=function(e,t){function i(){this.constructor=e}for(var n in t)r.call(t,n)&&(e[n]=t[n]);return i.prototype=t.prototype,e.prototype=new i,e.__super__=t.prototype,e};e=this.Mixin=typeof exports!="undefined"?exports:{},e.Core||(e.Core={}),e.VERSION="0.1.5",n=this._;if(!n&&typeof require!="undefined")try{n=require("lodash")}catch(s){try{n=require("underscore")}catch(s){({})}}return n&&n.hasOwnProperty("_")&&(n=n._),n||(n={}),e._=n,n.isArray||(n.isArray=function(e){return Object.prototype.toString.call(e)==="[object Array]"}),n.isString||(n.isString=function(e){return!!(e===""||e&&e.charCodeAt&&e.substr)}),n.isFunction||(n.isFunction=function(e){return!!(e&&e.constructor&&e.call&&e.apply)}),n.isEmpty||(n.isEmpty=function(e){var t,r;if(n.isArray(e)||n.isString(e))return e.length===0;for(t in e)return r=e[t],!1;return!0}),n.classOf||(n.classOf=function(e){return e instanceof Object?e.prototype&&e.prototype.constructor&&e.prototype.constructor.name?e.prototype.constructor.name:e.constructor&&e.constructor.name?e.constructor.name:void 0:void 0}),n.size||(n.size=function(e){var t,n;t=0;for(n in e)t++;return t}),n.find||(n.find=function(e,t){var n,r,i;for(r=0,i=e.length;r=0){i=this.instance_records[r];if(i.mix_target===e&&i.destroyMixin(t)){s=!0,n.isEmpty(i.initialized_mixins)&&(i.destroy(),this.instance_records.splice(r,1));if(t)return!0}r--}return s},t.prototype._getInstanceRecord=function(e){var t,n,r,i;i=this.instance_records;for(n=0,r=i.length;n1){s=i[1];if(!(n.isString(s)&&t.isAvailable(s)||n.isArray(s)&&s.length>=1&&n.isString(s[0])&&t.isAvailable(s[0])))return u.apply(this,arguments),r}for(a=0,f=i.length;a1){l=Array.prototype.slice.call(arguments,1);for(o=0,a=l.length;o1?e[1]:void 0;if(!n.keypathExists(this.owner,r))throw new Error("Mixin.AutoMemory: property '"+r+"' doesn't exist on '"+n.classOf(this.owner)+"'");if(t&&!n.isFunction(t)&&!n.isString(t))throw new Error("Mixin.AutoMemory: unexpected function reference for property '"+r+"' on '"+n.classOf(this.owner)+"'")},t.prototype._destroyEntry=function(e){var t,r,i,s,o,u,a,f;r=e[0],t=e.length>1?e[1]:void 0;if(!t){i=n.keypathValueOwner(this.owner,r);if(!i)throw new Error("Mixin.AutoMemory: property '"+r+"' doesn't exist on '"+n.classOf(this.owner)+"'");i[r]=null;return}o=n.keypath(this.owner,r);if(!o)return;if(n.isFunction(t))t.apply(this.owner,[o].concat(e.length>2?e.slice(2):[]));else if(n.isFunction(o[t]))o[t].apply(o,e.length>2?e.slice(2):[]);else{f=e.slice(1);for(u=0,a=f.length;ue.Subscription.TYPE.EXCLUSIVE)throw new Error("Mixin.Subscriptions: Mixin.Subscription.TYPE is invalid");this.subscription_links=[]}return t.prototype.addSubscriber=function(t,n,r){return this.subscription_type===e.Subscription.TYPE.EXCLUSIVE&&this.removeSubscribers(function(e){return e.mustKeepUntilDestroyed()}),this.subscription_links.push(new e.Subscriptions._SubscriptionLink(this,t,n,r))},t.prototype.removeSubscriber=function(e,t,r){var i;i=n.find(this.subscription_links,function(n){return e===n.subscriber&&t===n.notification_callback});if(!i)throw new Error("Mixin.Subscriptions.removeSubscriber: subscription '"+r+"' does not exist for '"+n.classOf(e)+"'");return n.remove(this.subscription_links,i),i.destroy()},t.prototype.subscribers=function(e){var t,n,r,i;i=this.subscription_links;for(n=0,r=i.length;n1){s=i[1];if(!(n.isString(s)&&this.hasSubscription(s)||n.isArray(s)&&s.length>=1&&n.isString(s[0])&&this.hasSubscription(s[0])))return a.apply(this,Array.prototype.slice.call(arguments,1)),this}for(f=0,l=i.length;f1){o=s[1];if(!(n.isString(o)&&this.hasSubscription(o)||n.isArray(o)&&o.length>=1&&n.isString(o[0])&&this.hasSubscription(o[0])))return f.apply(this,Array.prototype.slice.call(arguments,1)),this}for(l=0,c=s.length;l