backbone-decorators
Advanced tools
Comparing version 0.0.4 to 0.0.6
@@ -20,2 +20,5 @@ (function (global, factory) { | ||
return function (target, name, descriptor) { | ||
if (target.events && !_.has(target, 'events')) { | ||
target.events = _.clone(target.events); | ||
} | ||
if (!target.events) { | ||
@@ -22,0 +25,0 @@ target.events = {}; |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("underscore"),require("backbone")):"function"==typeof define&&define.amd?define(["exports","underscore","backbone"],t):t(e.Decorators={},e._,e.Backbone)}(this,function(e,t,r){"use strict";function o(e){return function(r,o,n){if(r.events||(r.events={}),t.isFunction(r.events))throw new Error("The on decorator is not compatible with an events method");if(!e)throw new Error("The on decorator requires an eventName argument");return r.events[e]=o,n}}function n(e){return function(t){t.prototype.tagName=e}}function i(e){return function(t){if(!(e.prototype instanceof r.Model))throw new Error("The model decorator takes either a single argument that should be an instance of Backbone.Model");t.prototype.model=e}}function a(e){return function(r){if(!t.isString(e))throw new Error("The comparator decorator takes either a single argument that should be a string");r.prototype.comparator=e}}function u(){for(var e=arguments.length,r=Array(e),o=0;e>o;o++)r[o]=arguments[o];return function(e){var o=e.prototype.defaults||{},n=r[0],i=r[1];if(t.isObject(n))t.extend(o,n);else{if(!t.isString(n)||t.isUndefined(i))throw new Error("The defaults decorator takes either a single object as an argument or a key and value");o[n]=i}e.prototype.defaults=o}}function s(e){return function(r,o,n){if(r.routes||(r.routes={}),t.isFunction(r.routes))throw new Error("The route decorator is not compatible with a route method");if(!e)throw new Error("The route decorator requires an route string argument");return r.routes[e]=o,n}}function c(e){return function(r,o,n){if(r.modelEvents||(r.modelEvents={}),t.isFunction(r.modelEvents))throw new Error("The onModel decorator is not compatible with a modelEvents method");if(!e)throw new Error("The onModel decorator requires an eventName argument");return r.modelEvents[e]=o,n}}function l(e){return function(r,o,n){if(r.collectionEvents||(r.collectionEvents={}),t.isFunction(r.collectionEvents))throw new Error("The onCollection decorator is not compatible with a collectionEvents method");if(!e)throw new Error("The onCollection decorator requires an eventName argument");return r.collectionEvents[e]=o,n}}function f(e){return function(t){t.prototype.template=e}}function d(e){return function(t){t.prototype.childView=e}}function h(e){return function(t){t.prototype.childViewContainer=e}}function p(){for(var e=arguments.length,r=Array(e),o=0;e>o;o++)r[o]=arguments[o];return function(e){var o=e.prototype.ui||{},n=r[0],i=r[1];if(t.isObject(n))t.extend(o,r[0]);else{if(!t.isString(n)||!t.isString(i))throw new Error("The ui decorator takes either a single object as an argument or a key and value string");o[n]=i}e.prototype.ui=o}}function m(e,r,o){var n=Object.getPrototypeOf(e)[r];if(!t.isFunction(n))throw new Error("The useSuper method requires the parent class to implement this function somewhere on its prototype chain");return o.value=function(){for(var e=arguments.length,t=Array(e),r=0;e>r;r++)t[r]=arguments[r];n.apply(this,t)},o}function g(e){return function(o){if(!r.LocalStorage)throw new Error("The localStorage decorator requires Backbone.LocalStorage to have been loaded before use");if(!t.isString(e))throw new Error("The localStorage decorator requires a single string argument which will serve as the localStorage key");o.prototype.localStorage=new r.LocalStorage(e)}}function w(e,r){return function(o,n,i){if(o.radioRequests||(o.radioRequests={}),t.isFunction(o.radioRequests))throw new Error("The replyRadio decorator is not compatible with a radioRequests method");if(!t.isString(e)||!t.isString(r))throw new Error("The replyRadio decorator requires 2 arguments, a channel and a request string.");return o.radioRequests[e+" "+r]=n,i}}t="default"in t?t["default"]:t,r="default"in r?r["default"]:r,e.on=o,e.tagName=n,e.model=i,e.comparator=a,e.defaults=u,e.route=s,e.onModel=c,e.onCollection=l,e.template=f,e.childView=d,e.childViewContainer=h,e.ui=p,e.useSuper=m,e.localStorage=g,e.replyRadio=w}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("underscore"),require("backbone")):"function"==typeof define&&define.amd?define(["exports","underscore","backbone"],t):t(e.Decorators={},e._,e.Backbone)}(this,function(e,t,r){"use strict";function o(e){return function(r,o,n){if(r.events&&!t.has(r,"events")&&(r.events=t.clone(r.events)),r.events||(r.events={}),t.isFunction(r.events))throw new Error("The on decorator is not compatible with an events method");if(!e)throw new Error("The on decorator requires an eventName argument");return r.events[e]=o,n}}function n(e){return function(t){t.prototype.tagName=e}}function i(e){return function(t){if(!(e.prototype instanceof r.Model))throw new Error("The model decorator takes either a single argument that should be an instance of Backbone.Model");t.prototype.model=e}}function a(e){return function(r){if(!t.isString(e))throw new Error("The comparator decorator takes either a single argument that should be a string");r.prototype.comparator=e}}function u(){for(var e=arguments.length,r=Array(e),o=0;e>o;o++)r[o]=arguments[o];return function(e){var o=e.prototype.defaults||{},n=r[0],i=r[1];if(t.isObject(n))t.extend(o,n);else{if(!t.isString(n)||t.isUndefined(i))throw new Error("The defaults decorator takes either a single object as an argument or a key and value");o[n]=i}e.prototype.defaults=o}}function s(e){return function(r,o,n){if(r.routes||(r.routes={}),t.isFunction(r.routes))throw new Error("The route decorator is not compatible with a route method");if(!e)throw new Error("The route decorator requires an route string argument");return r.routes[e]=o,n}}function c(e){return function(r,o,n){if(r.modelEvents||(r.modelEvents={}),t.isFunction(r.modelEvents))throw new Error("The onModel decorator is not compatible with a modelEvents method");if(!e)throw new Error("The onModel decorator requires an eventName argument");return r.modelEvents[e]=o,n}}function l(e){return function(r,o,n){if(r.collectionEvents||(r.collectionEvents={}),t.isFunction(r.collectionEvents))throw new Error("The onCollection decorator is not compatible with a collectionEvents method");if(!e)throw new Error("The onCollection decorator requires an eventName argument");return r.collectionEvents[e]=o,n}}function f(e){return function(t){t.prototype.template=e}}function d(e){return function(t){t.prototype.childView=e}}function h(e){return function(t){t.prototype.childViewContainer=e}}function p(){for(var e=arguments.length,r=Array(e),o=0;e>o;o++)r[o]=arguments[o];return function(e){var o=e.prototype.ui||{},n=r[0],i=r[1];if(t.isObject(n))t.extend(o,r[0]);else{if(!t.isString(n)||!t.isString(i))throw new Error("The ui decorator takes either a single object as an argument or a key and value string");o[n]=i}e.prototype.ui=o}}function m(e,r,o){var n=Object.getPrototypeOf(e)[r];if(!t.isFunction(n))throw new Error("The useSuper method requires the parent class to implement this function somewhere on its prototype chain");return o.value=function(){for(var e=arguments.length,t=Array(e),r=0;e>r;r++)t[r]=arguments[r];n.apply(this,t)},o}function g(e){return function(o){if(!r.LocalStorage)throw new Error("The localStorage decorator requires Backbone.LocalStorage to have been loaded before use");if(!t.isString(e))throw new Error("The localStorage decorator requires a single string argument which will serve as the localStorage key");o.prototype.localStorage=new r.LocalStorage(e)}}function w(e,r){return function(o,n,i){if(o.radioRequests||(o.radioRequests={}),t.isFunction(o.radioRequests))throw new Error("The replyRadio decorator is not compatible with a radioRequests method");if(!t.isString(e)||!t.isString(r))throw new Error("The replyRadio decorator requires 2 arguments, a channel and a request string.");return o.radioRequests[e+" "+r]=n,i}}t="default"in t?t["default"]:t,r="default"in r?r["default"]:r,e.on=o,e.tagName=n,e.model=i,e.comparator=a,e.defaults=u,e.route=s,e.onModel=c,e.onCollection=l,e.template=f,e.childView=d,e.childViewContainer=h,e.ui=p,e.useSuper=m,e.localStorage=g,e.replyRadio=w}); | ||
//# sourceMappingURL=backbone-decorators.min.js.map |
{ | ||
"name": "backbone-decorators", | ||
"version": "0.0.4", | ||
"version": "0.0.6", | ||
"description": "ES2016 Decorators for Backbone and Marionette", | ||
@@ -24,3 +24,3 @@ "main": "dist/backbone-decorators.js", | ||
"dependencies": { | ||
"backbone": "1.0.0 - 1.2.3", | ||
"backbone": "^1.0.0", | ||
"underscore": "1.4.4 - 1.8.3" | ||
@@ -32,2 +32,3 @@ }, | ||
"babelify": "^6.0.0", | ||
"backbone.marionette": "^2.4.4", | ||
"browserify": "^11.0.1", | ||
@@ -34,0 +35,0 @@ "chai": "^3.2.0", |
@@ -17,1 +17,4 @@ # backbone-decorators | ||
,/backbone-decorators#info=devDependencies) | ||
This repo is not actively maintained and not necessarily safe to use in production. If you're interested in contributing and growing it, please open a few PRs that show the direction you want to take it and we can discuss. |
@@ -9,2 +9,24 @@ import _ from 'underscore'; | ||
function onDecoratorFactory(decoratorName, propertyName) { | ||
return function(eventName) { | ||
return function(target, name, descriptor) { | ||
if (!eventName) { | ||
throw new Error(`The ${decoratorName} decorator requires an eventName argument`); | ||
} | ||
if (_.isFunction(target[propertyName])) { | ||
throw new Error(`The ${decoratorName} decorator is not compatible with ${propertyName} as method form`); | ||
return; | ||
} | ||
if (target[propertyName] && !_.has(target, propertyName)) { | ||
target[propertyName] = _.clone(target[propertyName]); | ||
} | ||
if (!target[propertyName]) { | ||
target[propertyName] = {}; | ||
} | ||
target[propertyName][eventName] = name; | ||
return descriptor; | ||
}; | ||
}; | ||
} | ||
// Backbone Decorators | ||
@@ -14,21 +36,3 @@ | ||
export function on(eventName) { | ||
return function(target, name, descriptor) { | ||
if (target.events && !_.has(target, 'events')) { | ||
target.events = _.clone(target.events) | ||
} | ||
if (!target.events) { | ||
target.events = {}; | ||
} | ||
if (_.isFunction(target.events)) { | ||
throw new Error('The on decorator is not compatible with an events method'); | ||
return; | ||
} | ||
if (!eventName) { | ||
throw new Error('The on decorator requires an eventName argument'); | ||
} | ||
target.events[eventName] = name; | ||
return descriptor; | ||
}; | ||
} | ||
export const on = onDecoratorFactory('on', 'events'); | ||
@@ -103,36 +107,6 @@ export function tagName(value) { | ||
export function onModel(eventName) { | ||
return function(target, name, descriptor) { | ||
if (!target.modelEvents) { | ||
target.modelEvents = {}; | ||
} | ||
if (_.isFunction(target.modelEvents)) { | ||
throw new Error('The onModel decorator is not compatible with a modelEvents method'); | ||
return; | ||
} | ||
if (!eventName) { | ||
throw new Error('The onModel decorator requires an eventName argument'); | ||
} | ||
target.modelEvents[eventName] = name; | ||
return descriptor; | ||
}; | ||
} | ||
export const onModel = onDecoratorFactory('onModel', 'modelEvents'); | ||
export const onCollection = onDecoratorFactory('onCollection', 'modelEvents'); | ||
export const onChild = onDecoratorFactory('onChild', 'childEvents'); | ||
export function onCollection(eventName) { | ||
return function(target, name, descriptor) { | ||
if (!target.collectionEvents) { | ||
target.collectionEvents = {}; | ||
} | ||
if (_.isFunction(target.collectionEvents)) { | ||
throw new Error('The onCollection decorator is not compatible with a collectionEvents method'); | ||
return; | ||
} | ||
if (!eventName) { | ||
throw new Error('The onCollection decorator requires an eventName argument'); | ||
} | ||
target.collectionEvents[eventName] = name; | ||
return descriptor; | ||
}; | ||
} | ||
export function template(value) { | ||
@@ -139,0 +113,0 @@ return function decorator(target) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
77637
27
690
20
34
1
+ Addedbackbone@1.6.0(transitive)
- Removedbackbone@1.2.3(transitive)
Updatedbackbone@^1.0.0