.derive()
method allows to deref other derivable? Will they be tracked then? 2) less API surface 3) consistent pattern for accessing derivable value d.get()
vs. d.derive(v => ...)
deriveInWorker<T, R>(source: Derivation<T>, derive: (value: T) => R): Derivation<?R>
null
if result isn't ready yet
source
and submit task to a worker and put result eventually into another atom I return from deriveInWorker
. Then (important) I want not to do any work if there's no reactions active on the derivation I return.
I'm trying to build a game with DerivableJS
https://gist.github.com/mruzekw/84a43be6490ae532515e90252933a38f
It's simple. The user is shown a 5x5 matrix of squares. Nine of them are highlighted for 5 seconds. Then the user has to select those squares to win the game.
You can find a demo here: http://mruzekw.github.io/recall-reactjs/
I'm currently defining when the player has won. I currently have:
let playerWon = gameOver.and(curBoard.derive((curBoard) => {
return isCorrectSelection(
expectedBoard,
curBoard.toJS()
);
}))
But I think I'm missing something cause it's not working...
@mruzekw Your use of setTimeout
seems fine to me. You can change
let gameOver = turnCount.derive((count) => {
return count === 9;
});
to
const gameOver = turnCount.is(9);
Also, if you keep expectedBoard
as Immutable data held in an atom, then you don't need isCorrectSelection
and you can just define playerWon
as
const playerWon = gameOver.and(curBoard.is(expectedBoard));
Otherwise, looks really nice :)