New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

angular-observe

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-observe - npm Package Compare versions

Comparing version 2.0.3 to 3.0.0

compat/most.js

145

dist/angular-observe.js

@@ -10,3 +10,3 @@ (function webpackUniversalModuleDefinition(root, factory) {

root["AngularObserve"] = factory(root["angular"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_1__) {
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__) {
return /******/ (function(modules) { // webpackBootstrap

@@ -58,4 +58,10 @@ /******/ // The module cache

var Angular = __webpack_require__(1);
module.exports = __webpack_require__(1);
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
var Angular = __webpack_require__(2);
module.exports = 'filearts.angularObserve';

@@ -65,3 +71,25 @@

mod.directive('asyncBind', ['$compile', '$q', '$rootScope', '$timeout', function ($compile, $q, $rootScope, $timeout) {
mod.provider('asyncBindConfig', [function () {
this.fromValue = function () {
throw new Error('You need to overwrite `asyncBindConfig.fromValue`.');
};
this.fromPromise = function () {
throw new Error('You need to overwrite `asyncBindConfig.fromPromise`.');
};
this.map = function () {
throw new Error('You need to overwrite `asyncBindConfig.map`.');
};
this.switchMap = function () {
throw new Error('You need to overwrite `asyncBindConfig.switchMap`.');
};
this.$get = function () {
return this;
};
}]);
mod.directive('asyncBind', ['$compile', '$q', '$rootScope', '$timeout', 'asyncBindConfig', function ($compile, $q, $rootScope, $timeout, asyncBindConfig) {
return {

@@ -73,4 +101,8 @@ restrict: 'EA',

function compile(tElement) {
var stateLinkFunctions = getStateLinkFunctions(tElement);
function compile(tElement, tAttrs) {
var sourceSpec = (tAttrs.asyncBind || tAttrs.source).split(/\s+as\s+/i);
var sourcePath = sourceSpec.shift().split('.');
var publishAlias = sourceSpec[0] || '$value';
var sourceModel = sourcePath.shift();
var stateLinkFunctions = getStateLinkFunctions(tElement, publishAlias);

@@ -83,4 +115,2 @@ return function postLink($scope, $element, $attrs) {

var sourceModel = $attrs.asyncBind || $attrs.source;
$element.empty();

@@ -91,21 +121,36 @@

subscription.unsubscribe();
subscription = null;
}
subscription = follow(sourcePath, source).subscribe(onNext, onError, onComplete);
setState('loading');
// Lift the source to an Observable-compatible interface
var observable = source && typeof source.subscribe === 'function'
? source
: source && typeof source.then === 'function'
? liftPromise(source)
: liftValue(source);
function atPath(path) {
var first = path.shift();
var rest = path;
return function (next) {
var child = next[first];
return child
? follow(rest, child)
: asyncBindConfig.fromValue();
};
}
// Subscribe to the observable
subscription = observable.subscribe(onNext, onError, onComplete);
function follow(path, source) {
var observable = lift(source);
return path.length
? asyncBindConfig.switchMap.call(observable, atPath(path))
: observable;
}
});
// Unsubscribe when this element is destroyed
// subscription when this element is destroyed
$scope.$on('$destroy', function() {
if (subscription) {
subscription.unsubscribe();
subscription = null;
}

@@ -115,6 +160,6 @@ });

function onNext(val) {
var forceLink = !isPrimitive(isolateScope.$value)
var forceLink = !isPrimitive(isolateScope[publishAlias])
|| !isPrimitive(val);
isolateScope.$value = val;
isolateScope[publishAlias] = val;

@@ -172,56 +217,12 @@ setState('active', forceLink);

function liftPromise(source) {
return {
subscribe: function (onNext, onError, onComplete) {
// I don't want to depend on any single Promise implementation
// so I can't rely on re-throwing the error. Instead, I guard
// on `failed` for the invocation of `onComplete`.
var failed = false;
var _onNext = function (val) {
onNext(val);
return val;
};
var _onError = function (val) {
onError(val);
failed = true;
};
var _onComplete = function () {
if (!failed) {
onComplete();
}
};
source.then(_onNext, _onError, onNext)
.then(_onComplete);
return {
unsubscribe: Angular.noop,
};
}
};
function lift(source) {
return source && typeof source.subscribe === 'function'
? source
: source && typeof source.then === 'function'
? asyncBindConfig.fromPromise(source)
: asyncBindConfig.fromValue(source);
}
function liftValue(source) {
return {
subscribe: function (onNext, onError, onComplete) {
// We are already using Angular so let's just leverage
// an existing service (`$timeout`) to fire the `onNext` and
// `onComplete` callbacks asynchronously.
$timeout(onNext.bind(null, source), 0, false)
.then(onComplete);
return {
unsubscribe: Angular.noop,
};
}
};
}
function getStateLinkFunctions(tElement) {
function getStateLinkFunctions(tElement, publishAlias) {
var stateLinkFunctions = {};

@@ -260,3 +261,3 @@ var stateTemplates = {

if (!template.length) {
template.push(document.createTextNode('{{$value}}'));
template.push(document.createTextNode('{{' + publishAlias + '}}'));
}

@@ -276,6 +277,6 @@

/***/ },
/* 1 */
/* 2 */
/***/ function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
module.exports = __WEBPACK_EXTERNAL_MODULE_2__;

@@ -282,0 +283,0 @@ /***/ }

@@ -1,1 +0,1 @@

!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n(require("angular")):"function"==typeof define&&define.amd?define(["angular"],n):"object"==typeof exports?exports.AngularObserve=n(require("angular")):e.AngularObserve=n(e.angular)}(this,function(e){return function(e){function n(t){if(r[t])return r[t].exports;var o=r[t]={exports:{},id:t,loaded:!1};return e[t].call(o.exports,o,o.exports,n),o.loaded=!0,o.exports}var r={};return n.m=e,n.c=r,n.p="",n(0)}([function(e,n,r){var t=r(1);e.exports="filearts.angularObserve";var o=t.module(e.exports,[]);o.directive("asyncBind",["$compile","$q","$rootScope","$timeout",function(e,n,r,o){function u(e){var n=a(e);return function(e,t,o){function u(e){function n(e){var n=typeof e;return"boolean"===n||"number"===n||"string"===n}var r=!n(v.$value)||!n(e);v.$value=e,f("active",r)}function a(e){f("complete")}function s(e){v.$error=e,f("error")}function f(e,r){if(r||e!==l){var o=n[e];if(p&&p.$destroy(),!o)return void t.empty();p=v.$new(),l=e,o(p,function(e){t.empty(),t.append(e)})}v.$root.$$phase||v.$digest(!0)}var p,l,d,v=r.$new(!0,e),b=o.asyncBind||o.source;t.empty(),e.$watch(b,function(e){d&&d.unsubscribe(),f("loading");var n=e&&"function"==typeof e.subscribe?e:e&&"function"==typeof e.then?c(e):i(e);d=n.subscribe(u,s,a)}),e.$on("$destroy",function(){d&&d.unsubscribe()})}}function c(e){return{subscribe:function(n,r,o){var u=!1,c=function(e){return n(e),e},i=function(e){r(e),u=!0},a=function(){u||o()};return e.then(c,i,n).then(a),{unsubscribe:t.noop}}}}function i(e){return{subscribe:function(n,r,u){return o(n.bind(null,e),0,!1).then(u),{unsubscribe:t.noop}}}}function a(n){var r={},o={loading:[],active:[],error:[],complete:[]},u=[];t.forEach(n.contents(),function(e){switch(e.nodeName.toLowerCase()){case"loading":return o.loading.push(e);case"active":return o.active.push(e);case"error":return o.error.push(e);case"complete":return o.complete.push(e);default:return u.push(e)}});var c=!1;if(t.forEach(o,function(n,o){if(n.length){c=!0;var u=t.element(n).clone();r[o]=e(u)}}),!c){u.length||u.push(document.createTextNode("{{$value}}"));var i=t.element(u).clone();r.active=e(i),r.complete=e(i.clone())}return r}return{restrict:"EA",scope:!0,compile:u}}])},function(n,r){n.exports=e}])});
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n(require("angular")):"function"==typeof define&&define.amd?define(["angular"],n):"object"==typeof exports?exports.AngularObserve=n(require("angular")):e.AngularObserve=n(e.angular)}(this,function(e){return function(e){function n(t){if(r[t])return r[t].exports;var o=r[t]={exports:{},id:t,loaded:!1};return e[t].call(o.exports,o,o.exports,n),o.loaded=!0,o.exports}var r={};return n.m=e,n.c=r,n.p="",n(0)}([function(e,n,r){e.exports=r(2)},function(n,r){n.exports=e},function(e,n,r){var t=r(1);e.exports="filearts.angularObserve";var o=t.module(e.exports,[]);o.provider("asyncBindConfig",[function(){this.fromValue=function(){throw new Error("You need to overwrite `asyncBindConfig.fromValue`.")},this.fromPromise=function(){throw new Error("You need to overwrite `asyncBindConfig.fromPromise`.")},this.map=function(){throw new Error("You need to overwrite `asyncBindConfig.map`.")},this.switchMap=function(){throw new Error("You need to overwrite `asyncBindConfig.switchMap`.")},this.$get=function(){return this}}]),o.directive("asyncBind",["$compile","$q","$rootScope","$timeout","asyncBindConfig",function(e,n,r,o,i){function u(e,n){var t=(n.asyncBind||n.source).split(/\s+as\s+/i),o=t.shift().split("."),u=t[0]||"$value",s=o.shift(),f=a(e,u);return function(e,n,t){function a(e){function n(e){var n=typeof e;return"boolean"===n||"number"===n||"string"===n}var r=!n(g[u])||!n(e);g[u]=e,d("active",r)}function p(e){d("complete")}function l(e){g.$error=e,d("error")}function d(e,r){if(r||e!==h){var t=f[e];if(m&&m.$destroy(),!t)return void n.empty();m=g.$new(),h=e,t(m,function(e){n.empty(),n.append(e)})}g.$root.$$phase||g.$digest(!0)}var m,h,v,g=r.$new(!0,e);n.empty(),e.$watch(s,function(e){function n(e){var n=e.shift(),t=e;return function(e){var o=e[n];return o?r(t,o):i.fromValue()}}function r(e,r){var t=c(r);return e.length?i.switchMap.call(t,n(e)):t}v&&(v.unsubscribe(),v=null),v=r(o,e).subscribe(a,l,p),d("loading")}),e.$on("$destroy",function(){v&&(v.unsubscribe(),v=null)})}}function c(e){return e&&"function"==typeof e.subscribe?e:e&&"function"==typeof e.then?i.fromPromise(e):i.fromValue(e)}function a(n,r){var o={},i={loading:[],active:[],error:[],complete:[]},u=[];t.forEach(n.contents(),function(e){switch(e.nodeName.toLowerCase()){case"loading":return i.loading.push(e);case"active":return i.active.push(e);case"error":return i.error.push(e);case"complete":return i.complete.push(e);default:return u.push(e)}});var c=!1;if(t.forEach(i,function(n,r){if(n.length){c=!0;var i=t.element(n).clone();o[r]=e(i)}}),!c){u.length||u.push(document.createTextNode("{{"+r+"}}"));var a=t.element(u).clone();o.active=e(a),o.complete=e(a.clone())}return o}return{restrict:"EA",scope:!0,compile:u}}])}])});
{
"name": "angular-observe",
"version": "2.0.3",
"version": "3.0.0",
"description": "Angular directive for representing the different states of an Observable.",

@@ -28,4 +28,5 @@ "main": "./dist/angular-observe.js",

"devDependencies": {
"lodash": "^3.10.1",
"webpack": "^1.12.9"
}
}

@@ -7,2 +7,4 @@ # Introducing the `observe` directive

Here, `angular-observe` will convert `$scope.observable` into an `Observable` and subscribe to that observable.
```html

@@ -17,3 +19,3 @@ <div async-bind="observable">

### Example using only the implicit `active` state:
### Example using only the implicit `active` state and default scope alias

@@ -26,3 +28,19 @@ ```html

### Example using only the implicit `active` state and a custom scope alias
```html
<div async-bind="observable as currentValue">
<span>Current value: <code>{{currentValue}}</code></span>
</div>
```
### Example traversing a tree of higher-order `Observable`s
```html
<div async-bind="currentUser$.posts$.0.title as latestBlogTitle">
<span>The current user's latest blog post as the title: {{latestBlogTitle}}</span>
</div>
```
## How it works

@@ -36,5 +54,5 @@

`loading` | The `Observable` has not yet yielded its first value.
`active` | The `Observable` has yielded at least one value but has not yet completed or errored. The current value is available in the scope as `$value`.
`error` | The `Observable` has errored. If a previous valid value was yielded, that will still be available on `$value`. The error will be available as `$error`.
`complete` | The `Observable` has completed. If a previous valid value was yielded, that will still be available on `$value`.
`active` | The `Observable` has yielded at least one value but has not yet completed or errored. The current value is available in the scope as `$value` or the provided `alias`.
`error` | The `Observable` has errored. If a previous valid value was yielded, that will still be available on `$value` or the provided `alias`. The error will be available as `$error`.
`complete` | The `Observable` has completed. If a previous valid value was yielded, that will still be available on `$value` or the provided `alias`.

@@ -41,0 +59,0 @@ Each of the following states can have its own markup nested in an element with the same name as the state. For example, to show the current value, you would use:

@@ -7,3 +7,25 @@ var Angular = require('angular');

mod.directive('asyncBind', ['$compile', '$q', '$rootScope', '$timeout', function ($compile, $q, $rootScope, $timeout) {
mod.provider('asyncBindConfig', [function () {
this.fromValue = function () {
throw new Error('You need to overwrite `asyncBindConfig.fromValue`.');
};
this.fromPromise = function () {
throw new Error('You need to overwrite `asyncBindConfig.fromPromise`.');
};
this.map = function () {
throw new Error('You need to overwrite `asyncBindConfig.map`.');
};
this.switchMap = function () {
throw new Error('You need to overwrite `asyncBindConfig.switchMap`.');
};
this.$get = function () {
return this;
};
}]);
mod.directive('asyncBind', ['$compile', '$q', '$rootScope', '$timeout', 'asyncBindConfig', function ($compile, $q, $rootScope, $timeout, asyncBindConfig) {
return {

@@ -15,4 +37,8 @@ restrict: 'EA',

function compile(tElement) {
var stateLinkFunctions = getStateLinkFunctions(tElement);
function compile(tElement, tAttrs) {
var sourceSpec = (tAttrs.asyncBind || tAttrs.source).split(/\s+as\s+/i);
var sourcePath = sourceSpec.shift().split('.');
var publishAlias = sourceSpec[0] || '$value';
var sourceModel = sourcePath.shift();
var stateLinkFunctions = getStateLinkFunctions(tElement, publishAlias);

@@ -25,4 +51,2 @@ return function postLink($scope, $element, $attrs) {

var sourceModel = $attrs.asyncBind || $attrs.source;
$element.empty();

@@ -33,21 +57,36 @@

subscription.unsubscribe();
subscription = null;
}
subscription = follow(sourcePath, source).subscribe(onNext, onError, onComplete);
setState('loading');
// Lift the source to an Observable-compatible interface
var observable = source && typeof source.subscribe === 'function'
? source
: source && typeof source.then === 'function'
? liftPromise(source)
: liftValue(source);
function atPath(path) {
var first = path.shift();
var rest = path;
return function (next) {
var child = next[first];
return child
? follow(rest, child)
: asyncBindConfig.fromValue();
};
}
// Subscribe to the observable
subscription = observable.subscribe(onNext, onError, onComplete);
function follow(path, source) {
var observable = lift(source);
return path.length
? asyncBindConfig.switchMap.call(observable, atPath(path))
: observable;
}
});
// Unsubscribe when this element is destroyed
// subscription when this element is destroyed
$scope.$on('$destroy', function() {
if (subscription) {
subscription.unsubscribe();
subscription = null;
}

@@ -57,6 +96,6 @@ });

function onNext(val) {
var forceLink = !isPrimitive(isolateScope.$value)
var forceLink = !isPrimitive(isolateScope[publishAlias])
|| !isPrimitive(val);
isolateScope.$value = val;
isolateScope[publishAlias] = val;

@@ -114,56 +153,12 @@ setState('active', forceLink);

function liftPromise(source) {
return {
subscribe: function (onNext, onError, onComplete) {
// I don't want to depend on any single Promise implementation
// so I can't rely on re-throwing the error. Instead, I guard
// on `failed` for the invocation of `onComplete`.
var failed = false;
var _onNext = function (val) {
onNext(val);
return val;
};
var _onError = function (val) {
onError(val);
failed = true;
};
var _onComplete = function () {
if (!failed) {
onComplete();
}
};
source.then(_onNext, _onError, onNext)
.then(_onComplete);
return {
unsubscribe: Angular.noop,
};
}
};
function lift(source) {
return source && typeof source.subscribe === 'function'
? source
: source && typeof source.then === 'function'
? asyncBindConfig.fromPromise(source)
: asyncBindConfig.fromValue(source);
}
function liftValue(source) {
return {
subscribe: function (onNext, onError, onComplete) {
// We are already using Angular so let's just leverage
// an existing service (`$timeout`) to fire the `onNext` and
// `onComplete` callbacks asynchronously.
$timeout(onNext.bind(null, source), 0, false)
.then(onComplete);
return {
unsubscribe: Angular.noop,
};
}
};
}
function getStateLinkFunctions(tElement) {
function getStateLinkFunctions(tElement, publishAlias) {
var stateLinkFunctions = {};

@@ -202,3 +197,3 @@ var stateTemplates = {

if (!template.length) {
template.push(document.createTextNode('{{$value}}'));
template.push(document.createTextNode('{{' + publishAlias + '}}'));
}

@@ -205,0 +200,0 @@

@@ -1,5 +0,7 @@

module.exports = {
var _ = require('lodash');
var baseConfig = {
cache: true,
entry: {
'angular-observe': __dirname + "/src/angular-observe.js",
'angular-observe': __dirname + "/compat/none",
},

@@ -12,3 +14,3 @@ output: {

// publicPath: "/static/",
filename: "angular-observe.js",
filename: "[name].js",
},

@@ -24,2 +26,30 @@ externals: {

},
};
};
module.exports = [
baseConfig,
_.defaultsDeep({
entry: {
'angular-observe.rx': __dirname + '/compat/rx',
},
externals: {
'rx': 'rx',
},
}, baseConfig),
_.defaultsDeep({
entry: {
'angular-observe.most': __dirname + '/compat/most',
},
externals: {
'most': 'most',
},
}, baseConfig),
_.defaultsDeep({
entry: {
'angular-observe.rx.next': __dirname + '/compat/rx.next',
},
externals: {
'@reactivex/rx': '@reactivex/rx',
},
}, baseConfig),
];
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc