zen-observable
Advanced tools
Comparing version 0.1.6 to 0.1.8
{ | ||
"name": "zen-observable", | ||
"version": "0.1.6", | ||
"version": "0.1.8", | ||
"description": "An Implementation of ES Observables", | ||
"homepage": "https://github.com/zenparsing/zen-observable", | ||
"dependencies": { | ||
"es-observable-tests": "^0.1.8" | ||
"license": "MIT", | ||
"devDependencies": { | ||
"es-observable-tests": "^0.2.2" | ||
} | ||
} |
@@ -105,7 +105,7 @@ // === Non-Promise Job Queueing === | ||
function cleanupSubscription(observer) { | ||
function cleanupSubscription(subscription) { | ||
// Assert: observer._observer is undefined | ||
let cleanup = observer._cleanup; | ||
let cleanup = subscription._cleanup; | ||
@@ -117,3 +117,3 @@ if (!cleanup) | ||
// more than once | ||
observer._cleanup = undefined; | ||
subscription._cleanup = undefined; | ||
@@ -124,23 +124,21 @@ // Call the cleanup function | ||
function subscriptionClosed(observer) { | ||
function subscriptionClosed(subscription) { | ||
return observer._observer === undefined; | ||
return subscription._observer === undefined; | ||
} | ||
function closeSubscription(observer) { | ||
function closeSubscription(subscription) { | ||
if (subscriptionClosed(observer)) | ||
if (subscriptionClosed(subscription)) | ||
return; | ||
observer._observer = undefined; | ||
cleanupSubscription(observer); | ||
subscription._observer = undefined; | ||
cleanupSubscription(subscription); | ||
} | ||
function cleanupFromSubscription(subscription) { | ||
// TODO: Should we get the method out and apply it here, instead of | ||
// looking up the method at call time? | ||
return _=> { subscription.unsubscribe() }; | ||
} | ||
function createSubscription(observer, subscriber) { | ||
function Subscription(observer, subscriber) { | ||
@@ -153,18 +151,19 @@ // Assert: subscriber is callable | ||
// TODO: Should we check for a "next" method here? | ||
this._cleanup = undefined; | ||
this._observer = observer; | ||
let subscriptionObserver = new SubscriptionObserver(observer), | ||
subscription = new Subscription(subscriptionObserver), | ||
start = getMethod(observer, "start"); | ||
let start = getMethod(observer, "start"); | ||
if (start) | ||
start.call(observer, subscription); | ||
start.call(observer, this); | ||
if (subscriptionClosed(subscriptionObserver)) | ||
return subscription; | ||
if (subscriptionClosed(this)) | ||
return; | ||
observer = new SubscriptionObserver(this); | ||
try { | ||
// Call the subscriber function | ||
let cleanup = subscriber.call(undefined, subscriptionObserver); | ||
let cleanup = subscriber.call(undefined, observer); | ||
@@ -179,3 +178,3 @@ // The return value must be undefined, null, a subscription object, or a function | ||
subscriptionObserver._cleanup = cleanup; | ||
this._cleanup = cleanup; | ||
} | ||
@@ -187,17 +186,17 @@ | ||
// to the observer | ||
subscriptionObserver.error(e); | ||
return subscription; | ||
observer.error(e); | ||
return; | ||
} | ||
// If the stream is already finished, then perform cleanup | ||
if (subscriptionClosed(subscriptionObserver)) | ||
cleanupSubscription(subscriptionObserver); | ||
return subscription; | ||
if (subscriptionClosed(this)) | ||
cleanupSubscription(this); | ||
} | ||
function SubscriptionObserver(observer) { | ||
addMethods(Subscription.prototype = {}, { | ||
unsubscribe() { closeSubscription(this) } | ||
}); | ||
this._observer = observer; | ||
this._cleanup = undefined; | ||
function SubscriptionObserver(subscription) { | ||
this._subscription = subscription; | ||
} | ||
@@ -207,11 +206,11 @@ | ||
get closed() { return subscriptionClosed(this) }, | ||
next(value) { | ||
let subscription = this._subscription; | ||
// If the stream if closed, then return undefined | ||
if (subscriptionClosed(this)) | ||
if (subscriptionClosed(subscription)) | ||
return undefined; | ||
let observer = this._observer; | ||
let observer = subscription._observer; | ||
@@ -232,3 +231,3 @@ try { | ||
// If the observer throws, then close the stream and rethrow the error | ||
try { closeSubscription(this) } | ||
try { closeSubscription(subscription) } | ||
finally { throw e } | ||
@@ -240,8 +239,10 @@ } | ||
let subscription = this._subscription; | ||
// If the stream is closed, throw the error to the caller | ||
if (subscriptionClosed(this)) | ||
if (subscriptionClosed(subscription)) | ||
throw value; | ||
let observer = this._observer; | ||
this._observer = undefined; | ||
let observer = subscription._observer; | ||
subscription._observer = undefined; | ||
@@ -260,8 +261,7 @@ try { | ||
try { cleanupSubscription(this) } | ||
try { cleanupSubscription(subscription) } | ||
finally { throw e } | ||
} | ||
cleanupSubscription(this); | ||
cleanupSubscription(subscription); | ||
return value; | ||
@@ -272,8 +272,10 @@ }, | ||
let subscription = this._subscription; | ||
// If the stream is closed, then return undefined | ||
if (subscriptionClosed(this)) | ||
if (subscriptionClosed(subscription)) | ||
return undefined; | ||
let observer = this._observer; | ||
this._observer = undefined; | ||
let observer = subscription._observer; | ||
subscription._observer = undefined; | ||
@@ -289,8 +291,7 @@ try { | ||
try { cleanupSubscription(this) } | ||
try { cleanupSubscription(subscription) } | ||
finally { throw e } | ||
} | ||
cleanupSubscription(this); | ||
cleanupSubscription(subscription); | ||
return value; | ||
@@ -301,10 +302,2 @@ }, | ||
function Subscription(observer) { | ||
this._observer = observer; | ||
} | ||
addMethods(Subscription.prototype = {}, { | ||
unsubscribe() { closeSubscription(this._observer) } | ||
}); | ||
export function Observable(subscriber) { | ||
@@ -323,3 +316,3 @@ | ||
return createSubscription(observer, this._subscriber); | ||
return new Subscription(observer, this._subscriber); | ||
}, | ||
@@ -426,5 +419,7 @@ | ||
let done = false; | ||
enqueueJob(_=> { | ||
if (observer.closed) | ||
if (done) | ||
return; | ||
@@ -442,3 +437,3 @@ | ||
if (observer.closed) | ||
if (done) | ||
return; | ||
@@ -456,3 +451,3 @@ } | ||
if (observer.closed) | ||
if (done) | ||
return; | ||
@@ -472,2 +467,4 @@ } | ||
}); | ||
return _=> { done = true }; | ||
}); | ||
@@ -482,5 +479,7 @@ }, | ||
let done = false; | ||
enqueueJob(_=> { | ||
if (observer.closed) | ||
if (done) | ||
return; | ||
@@ -492,3 +491,3 @@ | ||
if (observer.closed) | ||
if (done) | ||
return; | ||
@@ -499,2 +498,4 @@ } | ||
}); | ||
return _=> { done = true }; | ||
}); | ||
@@ -501,0 +502,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
/*=esdown=*/(function(fn, name) { if (typeof exports !== 'undefined') fn(require, exports, module); else if (typeof self !== 'undefined') fn(void 0, name === '*' ? self : (name ? self[name] = {} : {})); })(function(require, exports, module) { 'use strict'; // === Non-Promise Job Queueing === | ||
/*=esdown=*/(function(fn, name) { if (typeof exports !== 'undefined') fn(exports, module); else if (typeof self !== 'undefined') fn(name === '*' ? self : (name ? self[name] = {} : {})); })(function(exports, module) { 'use strict'; // === Non-Promise Job Queueing === | ||
@@ -105,7 +105,7 @@ var enqueueJob = (function() { | ||
function cleanupSubscription(observer) { | ||
function cleanupSubscription(subscription) { | ||
// Assert: observer._observer is undefined | ||
var cleanup = observer._cleanup; | ||
var cleanup = subscription._cleanup; | ||
@@ -117,3 +117,3 @@ if (!cleanup) | ||
// more than once | ||
observer._cleanup = undefined; | ||
subscription._cleanup = undefined; | ||
@@ -124,23 +124,21 @@ // Call the cleanup function | ||
function subscriptionClosed(observer) { | ||
function subscriptionClosed(subscription) { | ||
return observer._observer === undefined; | ||
return subscription._observer === undefined; | ||
} | ||
function closeSubscription(observer) { | ||
function closeSubscription(subscription) { | ||
if (subscriptionClosed(observer)) | ||
if (subscriptionClosed(subscription)) | ||
return; | ||
observer._observer = undefined; | ||
cleanupSubscription(observer); | ||
subscription._observer = undefined; | ||
cleanupSubscription(subscription); | ||
} | ||
function cleanupFromSubscription(subscription) { | ||
// TODO: Should we get the method out and apply it here, instead of | ||
// looking up the method at call time? | ||
return function(_) { subscription.unsubscribe() }; | ||
} | ||
function createSubscription(observer, subscriber) { | ||
function Subscription(observer, subscriber) { | ||
@@ -153,18 +151,19 @@ // Assert: subscriber is callable | ||
// TODO: Should we check for a "next" method here? | ||
this._cleanup = undefined; | ||
this._observer = observer; | ||
var subscriptionObserver = new SubscriptionObserver(observer), | ||
subscription = new Subscription(subscriptionObserver), | ||
start = getMethod(observer, "start"); | ||
var start = getMethod(observer, "start"); | ||
if (start) | ||
start.call(observer, subscription); | ||
start.call(observer, this); | ||
if (subscriptionClosed(subscriptionObserver)) | ||
return subscription; | ||
if (subscriptionClosed(this)) | ||
return; | ||
observer = new SubscriptionObserver(this); | ||
try { | ||
// Call the subscriber function | ||
var cleanup$0 = subscriber.call(undefined, subscriptionObserver); | ||
var cleanup$0 = subscriber.call(undefined, observer); | ||
@@ -179,3 +178,3 @@ // The return value must be undefined, null, a subscription object, or a function | ||
subscriptionObserver._cleanup = cleanup$0; | ||
this._cleanup = cleanup$0; | ||
} | ||
@@ -187,17 +186,17 @@ | ||
// to the observer | ||
subscriptionObserver.error(e); | ||
return subscription; | ||
observer.error(e); | ||
return; | ||
} | ||
// If the stream is already finished, then perform cleanup | ||
if (subscriptionClosed(subscriptionObserver)) | ||
cleanupSubscription(subscriptionObserver); | ||
return subscription; | ||
if (subscriptionClosed(this)) | ||
cleanupSubscription(this); | ||
} | ||
function SubscriptionObserver(observer) { | ||
addMethods(Subscription.prototype = {}, { | ||
unsubscribe: function() { closeSubscription(this) } | ||
}); | ||
this._observer = observer; | ||
this._cleanup = undefined; | ||
function SubscriptionObserver(subscription) { | ||
this._subscription = subscription; | ||
} | ||
@@ -207,11 +206,11 @@ | ||
get closed() { return subscriptionClosed(this) }, | ||
next: function(value) { | ||
var subscription = this._subscription; | ||
// If the stream if closed, then return undefined | ||
if (subscriptionClosed(this)) | ||
if (subscriptionClosed(subscription)) | ||
return undefined; | ||
var observer = this._observer; | ||
var observer = subscription._observer; | ||
@@ -232,3 +231,3 @@ try { | ||
// If the observer throws, then close the stream and rethrow the error | ||
try { closeSubscription(this) } | ||
try { closeSubscription(subscription) } | ||
finally { throw e } | ||
@@ -240,8 +239,10 @@ } | ||
var subscription = this._subscription; | ||
// If the stream is closed, throw the error to the caller | ||
if (subscriptionClosed(this)) | ||
if (subscriptionClosed(subscription)) | ||
throw value; | ||
var observer = this._observer; | ||
this._observer = undefined; | ||
var observer = subscription._observer; | ||
subscription._observer = undefined; | ||
@@ -260,8 +261,7 @@ try { | ||
try { cleanupSubscription(this) } | ||
try { cleanupSubscription(subscription) } | ||
finally { throw e } | ||
} | ||
cleanupSubscription(this); | ||
cleanupSubscription(subscription); | ||
return value; | ||
@@ -272,8 +272,10 @@ }, | ||
var subscription = this._subscription; | ||
// If the stream is closed, then return undefined | ||
if (subscriptionClosed(this)) | ||
if (subscriptionClosed(subscription)) | ||
return undefined; | ||
var observer = this._observer; | ||
this._observer = undefined; | ||
var observer = subscription._observer; | ||
subscription._observer = undefined; | ||
@@ -289,8 +291,7 @@ try { | ||
try { cleanupSubscription(this) } | ||
try { cleanupSubscription(subscription) } | ||
finally { throw e } | ||
} | ||
cleanupSubscription(this); | ||
cleanupSubscription(subscription); | ||
return value; | ||
@@ -301,10 +302,2 @@ }, | ||
function Subscription(observer) { | ||
this._observer = observer; | ||
} | ||
addMethods(Subscription.prototype = {}, { | ||
unsubscribe: function() { closeSubscription(this._observer) } | ||
}); | ||
function Observable(subscriber) { | ||
@@ -323,3 +316,3 @@ | ||
return createSubscription(observer, this._subscriber); | ||
return new Subscription(observer, this._subscriber); | ||
}, | ||
@@ -426,5 +419,7 @@ | ||
var done = false; | ||
enqueueJob(function(_) { | ||
if (observer.closed) | ||
if (done) | ||
return; | ||
@@ -442,3 +437,3 @@ | ||
if (observer.closed) | ||
if (done) | ||
return; | ||
@@ -456,3 +451,3 @@ } | ||
if (observer.closed) | ||
if (done) | ||
return; | ||
@@ -472,2 +467,4 @@ } | ||
}); | ||
return function(_) { done = true }; | ||
}); | ||
@@ -482,5 +479,7 @@ }, | ||
var done = false; | ||
enqueueJob(function(_) { | ||
if (observer.closed) | ||
if (done) | ||
return; | ||
@@ -492,3 +491,3 @@ | ||
if (observer.closed) | ||
if (done) | ||
return; | ||
@@ -499,2 +498,4 @@ } | ||
}); | ||
return function(_) { done = true }; | ||
}); | ||
@@ -501,0 +502,0 @@ }, |
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
0
38616
1
980
- Removedes-observable-tests@^0.1.8
- Removedes-observable-tests@0.1.9(transitive)