Skip to content

Commit

Permalink
Fix observation of asyncComputed when invalidated before ever observed
Browse files Browse the repository at this point in the history
  • Loading branch information
jansav committed Feb 7, 2022
1 parent d5c8226 commit e554e27
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/injectable-react/src/asyncComputed/asyncComputed.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { noop } from 'lodash/fp';
import { computed, createAtom, observable, runInAction, untracked } from 'mobx';

const neutralizeObsoletePromiseSymbol = Symbol.for(
Expand All @@ -9,7 +10,7 @@ export default (getObservedPromise, pendingValue) => {

const pendingBox = observable.box(false);

let neutralizeObsoletePromise;
let neutralizeObsoletePromise = noop;

const syncValueBox = observable.box(pendingValue, {
name: 'sync-value-box-for-async-computed',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ describe('asyncComputed', () => {
}, 'some-pending-value');
});

it('given invalidated before observation, when observed, does not throw', () => {
someAsyncComputed.invalidate();

expect(() => {
observe(someAsyncComputed.value, () => {});
}).not.toThrow();
});

describe('when only status is observed but not value', () => {
beforeEach(() => {
observe(someAsyncComputed.pending, () => {});
Expand Down

0 comments on commit e554e27

Please sign in to comment.