question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Send previous state as the 3rd argument to store subscriptions

See original GitHub issue

What problem is this solving

I think the subscription feature is awesome, however it can be more versatile if it were targeted or at least revel what has changed. At least certain logic can behave differently or just sort of react to particular piece of the state.

This has always been a pain with Vuex subscriptions.

Proposed solution

onStoreStateChange (mutation, state, prevState) {
}

more like watches.

or at least allow us to do

store.$subscribe (onStoreStateChange, 'countables.inner.count')

which targets an inner prop of a state

Describe alternatives you’ve considered

usage of watch on the state data

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
posvacommented, Aug 16, 2022

Note events is dev only and comes from Vue

0reactions
fvlasenkocommented, Aug 16, 2022

You could not send events key together to the events path callback Otherwise, you have to write an extra field in the repository in order to understand what caused the change state: () => ({ size: { path: 'size', width: 1800, height: 2500, depth: 600, cover: { path: 'size.cover', //i want to remove this field state: false, value: 100, }, events.key -> ‘state’, events.path -> ‘size.cover’ I would like to see the full path to the parameter inside the object so that I can work with this path later

Read more comments on GitHub >

github_iconTop Results From Across the Web

subscribe API with state as an argument #303 - reduxjs/redux
Please pass both current and previous state to listeners. I really don't want to have to keep a reference to the previous state...
Read more >
Subscriptions - Apollo GraphQL Docs
Subscriptions are intended to be used to subscribe to external data changes, and have those received changes be stored in the cache. You...
Read more >
Accessing previous props or state with React Hooks
Leverage the useRef, useState, usePrevious, and useEffect React Hooks to access previous props and states from within functional components.
Read more >
Subscribe · Pullstate
Subscriptions are client-side only listeners to changes in your store's state. ... The third argument is the last watched value, passed as a...
Read more >
How to stop a subscription after the response to a service ...
To get the actual value that caused takeWhile to end the subscription, pass true as a second parameter to takeWhile ( inclusive ):...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found