ivantsov / redux-subscriber Goto Github PK
View Code? Open in Web Editor NEWSubscribe to changes in any part of redux state
Subscribe to changes in any part of redux state
I needed this library for a side project recently, but in my case, I needed to dispatch an action when the subscription callback is invoked.
Also because I was using redux-thunk extensively, I would like to have a similar convention where the callback receives via arguments, the dispatcher and state.
Because of that, I didn't want to make a pull request, but if you want to have a look and let me know what you think, I could continue working towards a PR.
Hi there! First of all, very nice idea, thanks for implementing this module! Pretty simple implementation and quite useful.
I was curious to know whether you considered returning subscribe
api when calling initSubscriber
.
See following example:
import {createStore} from 'redux';
import initSubscriber from 'redux-subscriber';
const store = createStore(...);
const subscriber = initSubscriber(store);
subscriber.subscribe('user.messages.count', state => {
// do something
});
I think that makes it very clear from where the subscribe
method come from.
Hi @ivantsov ) Your lib is very helpful in projects, thank you.
Recently I encountered such a phenomenon that when any action is activated inside the callback function, the callback function is called again and again.
The Redux website says that their subscription function allows the dispatch of actions inside the callback function.
What if I need to make a dispatch inside the callback function? Is this possible?
Thank you)
Subscribe callback is being fired twice when there is only one state change.
Code here:
import Subscriber from 'redux-subscriber'
import store from './my-store'
const subscribe = Subscriber(store)
subscribe('org.selected', state => {
console.log('RENDERING', 'org.selected') // this is being output twice per state change
renderSelection(state)
})
Can you think of a reason that the handler may be fired twice with only one action dispatched? Perhaps I'm missing something?
Note that when I comment out the redux-subscriber code and use the normal store.subscribe
method, it works as expected; the output shows once per action. Is it possible the subscriber is changing the way the store dispatches?
I have the following code which is straight forward
const subToNewDataChange = subscribe('newData', state => {
const random = Math.random() * (100 - 15) + 15;
this.setState({key:random }, function () {
this.forceUpdate();
}.bind(this));
})
But on Andriod only I'm the getting an error with setState not being a function, which If I understand correctly is a binding issue. What is confusing is that it's only happing on Andiord and it's somewhat random i.e. sometimes it works without any error which makes me think it has something to do with the package, not binding correctly any ideas?
@ivantsov Just a suggestion: https://www.npmjs.com/package/object-path-get seems a better fit for redux-subscriber.
Hi ivantsov great project, you have the easiest to understand subscribing package for redux I could find.
I'm only getting started using this project but I have noticed when subscribing to Boolean properties the project does not seem to pickup the changes.
For my project I have just changed the Boolean properties to an integer with 1/0 values
Cheers
mrjono1
Feel free to remove this issue, but I wasn't sure where to ask questions. I noticed there are no types in DefinitelyTyped. Have you heard of anyone that has created TS types for this API already? As a truly lazy dev, I'd like to reuse and recycle :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.