-
Notifications
You must be signed in to change notification settings - Fork 5
/
backbrace.min.js
6 lines (4 loc) · 2.94 KB
/
backbrace.min.js
1
2
3
4
5
6
// Backbrace.js 0.3.0
// (c) 2012 Patrick Williams, BitTorrent Inc.
// Backbrace may be freely distributed under the MIT license.
(function(){"use strict";function e(e,t){if(!e)throw t}function s(n){e(_.isString(n),"initial_selector takes a single argument");var r=n.split(t);e(_.isArray(r));var i=_.first(r);return e(_.isString(i),"initial_selector should return a string"),i}function o(n){e(_.isString(n));var r,i;return r=n.split(t),e(_.isArray(r)),i=null,r.length>1&&(i=_.chain(r).rest().reduce(function(e,n){return e?e+t+n:n}).value(),e(_.isString(i))),i}function u(t,n){e(_.toString(n));var r=_.clone(t||[]);return r.unshift(n),r}function a(e,t){var n,r,i;n=e||[],r=t||[];if(n.length!==r.length)return!1;for(i=0;i<n.length&&i<r.length;i++)if(n[i]!==r[i])return!1;return!0}function f(t,n,r,i,s){e(_.isNull(t)||_.isString(t)),e(_.isFunction(n)),t&&s&&!_.isUndefined(s.live)?s.live(t,n,r,u(i,s)):t||n.apply(r,u(i,s))}function l(t,n,i,s,f,l,c){var h,p;e(_.isFunction(t)),e(_.isString(n)),e(_.isFunction(i)),e(_.isString(s)),e(_.isFunction(f)),h=this,p=function(e,d,v,m){var g;e===s&&d===f&&v===l&&a(m,c)&&(g=o(s),g&&t(function(e){_.isFunction(e.die)&&e.die(g,d,v,u(m,e))}),h.off(n,i,h),r--,h.off("backbrace:die:"+s,p,h),r--)},h.on("backbrace:die:"+s,p,h),r++}var t=" ",n="*",r=0,i=0;this.Backbrace={setDelimiter:function(r){e(r!==",","cannot use , as a delimiter as it will prevent event callbacks from being set properly"),e(this.isClean(),"setting the delimiter after calling live can cause unexpected behavior"),e(r!==n,"setting the delimiter to the same value as the wildcard can cause unexpected behavior"),t=r},setWildcard:function(r){e(r!==",","cannot use , as a wildcard as it will prevent event callbacks from being set properly"),e(this.isClean(),"setting the wildcard after calling live can cause unexpected behavior"),e(r!==t,"setting the wildcard to the same value as the delimiter can cause unexpected behavior"),n=r},isClean:function(){return r===0&&i===0}};var c=function(t,n,r,s){return e(_.isString(t)),e(_.isFunction(n)),this.trigger("backbrace:die:"+t,t,n,r,s),i--,this};_.extend(Backbone.Collection.prototype,{die:c}),_.extend(Backbone.Model.prototype,{die:c}),_.extend(Backbone.Collection.prototype,{live:function(t,u,a,c){e(_.isString(t)),e(_.isFunction(u));var h,p,d,v,m,g,y;return i++,h=this,p=s(t),d=o(t),e(_.isString(p)),e(_.isNull(d)||_.isString(d)),v=_.bind(f,this,d,u,a,c),m=function(e){p===n?h.each(e):h.get(p)&&e(h.get(p))},m(v),g="add",y=p===n?v:function(e){e.id===p&&v(e)},h.on(g,y,h),r++,l.call(h,m,g,y,t,u,a,c),h}}),_.extend(Backbone.Model.prototype,{live:function(e,t,u,a){var c,h,p,d,v,m,g;return i++,c=this,h=s(e),p=o(e),d=_.bind(f,this,p,t,u,a),v=function(e){h===n?_.each(c.toJSON(),e):c.has(h)&&e(c.get(h),h)},v(d),h===n?(m="change",g=function(){_.each(c.changedAttributes(),function(e,t){_.isUndefined(c.previous(t))&&d(e)})}):(m="change:"+h,g=function(){var e;_.isUndefined(c.previous(h))&&(e=c.get(h),d(e))}),c.on(m,g,c),r++,l.call(c,v,m,g,e,t,u,a),c}})}).call(this);