Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Commit

Permalink
fix(ObjectObservable): check $value for unique value
Browse files Browse the repository at this point in the history
closes #45
  • Loading branch information
adriancarriger committed Jun 19, 2017
1 parent c0d66b6 commit 60c49f2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/database/object/afo-object-observable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('Object Observable', () => {
done();
}
});
objectObservable.uniqueNext('a value');
objectObservable.uniqueNext({$value: 'a value'});
});

it('should emulate a que for update', done => {
Expand Down
8 changes: 7 additions & 1 deletion src/database/object/afo-object-observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class AfoObjectObservable<T> extends ReplaySubject<T> {
* Only calls next if the new value is unique
*/
uniqueNext(newValue) {
if (this.updated > 1 || (stringify(this.previousValue) !== stringify(newValue) )) {
if (this.updated > 1 || (this.comparableValue(this.previousValue) !== this.comparableValue(newValue) )) {
this.previousValue = newValue;
this.next(newValue);
this.updated++;
Expand Down Expand Up @@ -164,4 +164,10 @@ export class AfoObjectObservable<T> extends ReplaySubject<T> {
private updateSubscribers() {
this.uniqueNext(unwrap(this.ref.$ref.key, this.value, () => this.value !== null));
}
private comparableValue(initialValue) {
if (initialValue && '$value' in initialValue) {
return stringify(initialValue.$value);
}
return stringify(initialValue);
}
}

0 comments on commit 60c49f2

Please sign in to comment.