Coder Social home page Coder Social logo

Comments (4)

voliva avatar voliva commented on June 1, 2024 2

Hey @d-krause thank you for flagging this up and coming up with a solution. The tutorial was affected by the changes on partitionByKey and we didn't update it.

I've already fixed the sandbox and a PR for updating the docs is already on the way re-rxjs/react-rxjs.org#59

Some clarification though, on the points you said that would need to be changed:

  1. The mergeWithKey call in App.tsx would need a .pipe( startWith( { payload: { id: 0, text: '' }, type: 'delete' } ));

It's not really needed. The observable returned by partitionByKey always emits immediately when someone subscribes to it, even if the source stream didn't emit anything. So it shouldn't really need the startWith

  1. The const [useTodos, todos$] = bind(keys$); would need to become const [useTodos, todos$] = bind(keys$.pipe(map(x => Array.from(x.keys))));

This is the place that had to be updated. But now partitionByKey doesn't return an observable of the list of keys, but an observable of the keys that were changed (either added or removed).

If you need to get a set of the keys at any given moment, utils also exports toKeySet() as a utility. The code then becomes:

const [useTodos, todos$] = bind(
  keys$.pipe(
    toKeySet(),
    map(set => Array.from(set))
  )
);
  1. The if(i === 0) condition would need to be removed from the groupedObservables$ map function call in the partitionByKey return value.

Same reason as above, partitionByKey doesn't emit all the current keys, only those that have changed. The condition i === 0 covers the first point you raised: Every new observer will have an emission of one single change of type "add" with all the keys that are currently active.

This was done for performance reasons, as re-emitting the complete set on every new emission didn't scale well for streams with thousands of events. When composing the streams down, in most cases you're only interested on the values that were changed, and if you need a list it's trivial to build it from the Observable of changes.

from react-rxjs.

voliva avatar voliva commented on June 1, 2024 1

@nktka unfortunately yes. I realised it when fixing the sandbox above.

Human error, sorry. What happened here is that when we did this change #232 we didn't immediately release it, hoping to bundle new changes into a minor version (we're still on 0.x.x). However, this did not happen, and one year later #302 fix came in, which we had to release. I forgot that we didn't release this breaking change as a separate minor version, so it got released as a patch.

It can't be reverted, as trying to revert it would be another violation of semversion. Fortunately, it only affects one function from the utility package, and the "migration path" is simple (use the provided toKeySet() operator). But that's no excuse, we will change the process to avoid this from happening again.

from react-rxjs.

nktka avatar nktka commented on June 1, 2024 1

@voliva Thanks for clarifying and a migration tip! Really enjoying the lib.

from react-rxjs.

nktka avatar nktka commented on June 1, 2024

sorry, but did you just introduce a breaking change with a PATCH version?

from react-rxjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.