Skip to content

Commit

Permalink
fix: reactivity in .subscribe() method
Browse files Browse the repository at this point in the history
  • Loading branch information
prevwong committed May 14, 2023
1 parent 3aac6a3 commit 5609f03
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/silly-pots-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rekajs/core': patch
---

Persist reactivity in .subscribe method
5 changes: 2 additions & 3 deletions packages/core/src/reka.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { Frame, FrameOpts } from './frame';
import { Head } from './head';
import { StateOpts, StateSubscriberOpts } from './interfaces';
import { ChangeListenerSubscriber, Observer } from './observer';
import { toJS } from './utils';

export class Reka {
id: string;
Expand Down Expand Up @@ -231,11 +230,11 @@ export class Reka {
*/
subscribe<C>(
collect: (reka: Reka) => C,
onCollect: (collected: C, prevCollected: C) => void,
onCollect: (collected: C, prevCollected: C | undefined) => void,
opts?: StateSubscriberOpts
) {
const dispose = reaction(
() => toJS(collect(this)),
() => collect(this),
(collected, prevCollected) => onCollect(collected, prevCollected),
{
fireImmediately: opts?.fireImmediately,
Expand Down

1 comment on commit 5609f03

@vercel
Copy link

@vercel vercel bot commented on 5609f03 May 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

reka – ./

rekajs.vercel.app
reka-git-main-prevwong.vercel.app
reka-prevwong.vercel.app
reka.js.org

Please sign in to comment.