Skip to content

Commit

Permalink
More naming changes from subscriber to observable
Browse files Browse the repository at this point in the history
  • Loading branch information
LFDM committed Apr 18, 2017
1 parent e41196d commit cff35ee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
18 changes: 9 additions & 9 deletions src/plugins/observable/index.js
Expand Up @@ -40,28 +40,28 @@ const createObservableFactory = (state, relationships, entityConfigs, entity, fn
}

fn(...args).then(
(res) => map_((subscription) => subscription.successCb(res), subscriptions),
(err) => map_((subscription) => subscription.errorCb(err), subscriptions)
(res) => map_((subscription) => subscription.onNext(res), subscriptions),
(err) => map_((subscription) => subscription.onError(err), subscriptions)
);
};

const subscriber = {
const observable = {
destroy: () => {
subscriber.alive = false;
observable.alive = false;
state.changeListeners = removeElement(changeListener, state.changeListeners);
subscriptions = [];
},
subscribe: (successCb, errorCb = noop) => {
const subscription = { successCb, errorCb };
subscribe: (onNext, onError = noop) => {
const subscription = { onNext, onError };
// add ourselves to the subscription list after the first initial call,
// so that we don't consume a change we triggered ourselves.
fn(...args).then(
(res) => {
successCb(res);
onNext(res);
subscriptions.push(subscription);
},
(err) => {
errorCb(err);
onError(err);
subscriptions.push(subscription);
}
);
Expand All @@ -71,7 +71,7 @@ const createObservableFactory = (state, relationships, entityConfigs, entity, fn
};

state.changeListeners.push(changeListener);
return subscriber;
return observable;
};

export const observable = () => ({ addListener, entityConfigs }) => {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/observable/index.spec.js
Expand Up @@ -201,6 +201,7 @@ describe('observable plugin', () => {
});
});

// this is different from e.g. rxjs, which immediately terminates a subscription on error
it('also invokes error callback in later stages of the subscription\'s lifecycle', () => {
const spy = sinon.spy();
const errSpy = sinon.spy();
Expand Down
4 changes: 2 additions & 2 deletions src/release.js
@@ -1,11 +1,11 @@
import { build } from './builder';
import { subscriber } from './plugins/subscriber';
import { observable } from './plugins/observable';
import { denormalizer } from './plugins/denormalizer';

module.exports = {
build,
plugins: {
subscriber,
observable,
denormalizer
}
};

0 comments on commit cff35ee

Please sign in to comment.