At the moment it is possible to inject equality-checking logic at the module level using the top-level function withEquality which returns a new instance of DerivableJS using the given equality-checking function.
It occurred to me recently that it would also make a lot of sense to be able to do this on a per-derivable basis. Maybe even more sense than at the module level.
It would look like this:
import { equals } from 'ramda'
const $Person = atom({name: "Steve"}).withEquality(equals);
$Person.react(({name}) => console.log(`name is ${name}`));
// $> name is Steve
$Person.set({name: "Steve"});
// ... no output (this would print the name again
// if using DerivableJS's standard equality function
// which only does strict-equality (===) checks if no .equals
// method is present on the arguments being compared)
At the moment it is possible to inject equality-checking logic at the module level using the top-level function
withEquality
which returns a new instance of DerivableJS using the given equality-checking function.It occurred to me recently that it would also make a lot of sense to be able to do this on a per-derivable basis. Maybe even more sense than at the module level.
It would look like this: