ng-current
Advanced tools
Comparing version 1.0.8 to 1.0.9
@@ -132,12 +132,13 @@ ;(function(angular) { | ||
* @param {*} data arbitrary data to select | ||
* @param {boolean} [applyModel] whether or not to apply model function against data | ||
* @param {boolean} [force] publish update even if the data is unchanged | ||
* @param {boolean} [model] whether or not to apply model function against data | ||
* @param {Object} object to use as representation of current state | ||
*/ | ||
this.select = function(name, data, applyModel) { | ||
this.select = function(name, data, force, model) { | ||
var old = $rootScope.current[name] | ||
// only publish update if the current value has changed | ||
if (!angular.equals(data, old)) { | ||
if (applyModel) { | ||
data = this.contexts[name].model(data) | ||
if (!angular.equals(data, old) || force) { | ||
if (model) { | ||
data = this.contexts[name].model(data) // FIXME - use $rootScope.context instead | ||
} | ||
@@ -144,0 +145,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(a){"use strict";var b=a.module("ng-current",[]);b.service("Contexts",["$log","$rootScope","$q",function(b,c,d){var e=this;this.contexts={},c.current={},this.register=function(a){this.contexts[a.name]=a.rels||[],a.refresh=e.refreshing(a),a.use=e.using(a),a.$$hasContext=!0,c.current[name]={}},this.refreshing=function(a){return function(c,e){var f=a[c];a.model||function(a){return a};f instanceof Function?d.when(f.call(a)).then(function(b){e(b instanceof Array?b.map(a.model,a):a.model(b))})["catch"](function(a){b.error("[ng-current.refreshing] failed to refresh Service integration point",a)}):b.error("[ng-current.refreshing] failed to find method on service",c)}},this.using=function(a){return function(c,d,f){a.$$hasContext?(f||a.refresh(c,d),e.subscribe(a.name,function(b){a.refresh(c,d),a.rels&&a.rels.length&&a.rels.forEach(function(a){e.publish(a,b)})})):b.error("[ng-current.using] malformed Service context, please ensure you have added `Contexts.register(this)` at the end of this service",a)}},this.clear=function(a){(e.contexts[a]||[]).forEach(function(a){delete c.current[a];var b=e.contexts[a];b instanceof Array&&b.length&&b.forEach(e.clear)})},this.select=function(b,d,f){var g=c.current[b];return a.equals(d,g)||(f&&(d=this.contexts[b].model(d)),c.current[b]=d,e.clear(b),e.publish(b,d)),d},this.current=function(a){return c.current[a]},this.currentOr=function(b,c){var d=this.current(b);return a.isObject(d)||a.isUndefined(c)?d:c},this.get=e.current,this.getOr=e.currentOr,this.subscribe=function(a,b){c.$on(a,function(a,c){b(c||{},a)})},this.publish=function(a,b){var d=e.contexts[a],f=d?[a].concat(d):[a];return f.forEach(function(a){if(a.constructor!==String)throw"rels must be Strings";c.$broadcast(a,b)}),b}}])}(angular),module&&exports&&module.exports===exports&&(module.exports="ng-current"); | ||
!function(a){"use strict";var b=a.module("ng-current",[]);b.service("Contexts",["$log","$rootScope","$q",function(b,c,d){var e=this;this.contexts={},c.current={},this.register=function(a){this.contexts[a.name]=a.rels||[],a.refresh=e.refreshing(a),a.use=e.using(a),a.$$hasContext=!0,c.current[name]={}},this.refreshing=function(a){return function(c,e){var f=a[c];a.model||function(a){return a};f instanceof Function?d.when(f.call(a)).then(function(b){e(b instanceof Array?b.map(a.model,a):a.model(b))})["catch"](function(a){b.error("[ng-current.refreshing] failed to refresh Service integration point",a)}):b.error("[ng-current.refreshing] failed to find method on service",c)}},this.using=function(a){return function(c,d,f){a.$$hasContext?(f||a.refresh(c,d),e.subscribe(a.name,function(b){a.refresh(c,d),a.rels&&a.rels.length&&a.rels.forEach(function(a){e.publish(a,b)})})):b.error("[ng-current.using] malformed Service context, please ensure you have added `Contexts.register(this)` at the end of this service",a)}},this.clear=function(a){(e.contexts[a]||[]).forEach(function(a){delete c.current[a];var b=e.contexts[a];b instanceof Array&&b.length&&b.forEach(e.clear)})},this.select=function(b,d,f,g){var h=c.current[b];return(!a.equals(d,h)||f)&&(g&&(d=this.contexts[b].model(d)),c.current[b]=d,e.clear(b),e.publish(b,d)),d},this.current=function(a){return c.current[a]},this.currentOr=function(b,c){var d=this.current(b);return a.isObject(d)||a.isUndefined(c)?d:c},this.get=e.current,this.getOr=e.currentOr,this.subscribe=function(a,b){c.$on(a,function(a,c){b(c||{},a)})},this.publish=function(a,b){var d=e.contexts[a],f=d?[a].concat(d):[a];return f.forEach(function(a){if(a.constructor!==String)throw"rels must be Strings";c.$broadcast(a,b)}),b}}])}(angular),module&&exports&&module.exports===exports&&(module.exports="ng-current"); |
{ | ||
"name": "ng-current", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "Relational context manager for Angular", | ||
@@ -5,0 +5,0 @@ "main": "ng-current.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27195
472