1
Mobx-utils/fromPromise.state不可觀察!爲什麼與'when'工作和'observe'或'intercept`不一致?
const { observable, when, reaction, intercept, observe, isObservable } = mobx;
const { fromPromise, whenWithTimeout } = mobxUtils;
const promise = fetch('https://jsonplaceholder.typicode.com/todos')
.then(res => res.json())
const result = fromPromise(promise);
console.assert(isObservable(result.state), 'state is NOT an isObservable');
/* WORKS!
when(
() => result.state !== "pending",
() => {
console.log("Got ", result.value)
}
);
*/
// NOT WORK, Why ?
observe(result, 'state', change => (console.log('observe', change)), true)
intercept(result, 'state', change => (console.log('intercept', change)));
reaction(
() => result.state,
state => console.log('reaction', state)
);
<script src="https://unpkg.com/[email protected]/lib/mobx.umd.js"></script>
<script src="https://unpkg.com/mobx-utils/mobx-utils.umd.js"></script>