frp-ts icon indicating copy to clipboard operation
frp-ts copied to clipboard

feat(core): add distinctUntilChanged operator

Open tamazlykar opened this issue 1 year ago • 4 comments

tamazlykar avatar Jul 16 '22 07:07 tamazlykar

☁️ Nx Cloud Report

We didn't find any information for the current pull request with the commit f6871372fdc7d27e4b3ba1789fb13fdba44f961c. You might need to set the 'NX_BRANCH' environment variable in your CI pipeline.

Check the Nx Cloud Github Integration documentation for more information.


Sent with 💌 from NxCloud.

nx-cloud[bot] avatar Jul 16 '22 07:07 nx-cloud[bot]

Hey @tamazlykar, what is the reasoning behind adding this operator? Property's are designed so that value comparison is an implementation detail and I wouldn't want to expose any kinds of "comparators" to the end user. By design, values are always compared by reference, if you need deep comparison this usually means the structure is mutated. Any kinds of mutations and similar impurities are out of scope of frp-ts

raveclassic avatar Jul 19 '22 13:07 raveclassic

Ok, I see you need deep comparison due to different object literals (different references) even their contents are the same. Well, I can't say such things are in the spirit of frp-ts as the intention is clearly to set the new reference and deep comparison looks like a "fix" for that. Instead I'd suggest moving the comparison out of the set to a condition wrapping that set.

const a = newAtom({ name: 'foo' })
a.set({ name: 'foo' }) // the intention is to push new object

if (!deepEqual(a.get(), {name: 'foo'})) { // the intention is to check deeply
  a.set({ name: 'foo' }) 
}

raveclassic avatar Jul 19 '22 13:07 raveclassic

ok found the original issue, linking https://github.com/raveclassic/frp-ts/issues/59

raveclassic avatar Jul 19 '22 14:07 raveclassic