Comments (20)
Hi there! With Observable Store only one store will be created to store all 8 entities (singleton). That allows a single store to be created but different services to have single responsibility (good for maintenance of course). For example, you might have the following:
YourStore
- customers property
- orders property
- settings property
CustomerService extends ObservableStore<YourStore>
- Would have functionality to get/set the state for customers
OrdersService extends ObservableStore<YourStore>
- Would have functionality to get/set the state for orders
SettingsService extends extends ObservableStore<YourStore>
- Would have functionality to get/set the state for settings
All 3 share the same store but only update what they're responsible for (customers, orders, settings respectively).
Your HTTP calls can now be separated into different services to keep things clean, but all 3 services would be interacting with the same store instance when they call setState() or getState(). Anyone that subscribes to state changes in a service such as SettingsService would only get changes that service caused in the store (changes to settings in this example). The same would apply to the other services.
Hope that helps.
Also, check out the included demos and you can see how multiple services can integrate with a single store (specifically the Angular demo).
from observable-store.
That really helped. Once I saw that the state object was being held as a singleton via a closure in the ObservableStore class, then it all became clear. Thanks.
from observable-store.
Awesome - have fun with it!
from observable-store.
Thanks! I had a deep dive into it, and have spotted a way of enhancing. Think it would benefit other users too. Would it be ok, if I were to submit a pull request?
from observable-store.
Absolutely. I'll have to take a look at it of course before accepting since my overall goal is to keep things super simple, but I'm definitely open to enhancements if they'll benefit others. Just depends on what is being done.
from observable-store.
Fantastic, thank you. Yes of course I totally understand, and simplicity is my goal too and what I really liked about your approach. Will jump on it shortly as I need to enhance it for my own use too. Hopefully you will like it.
from observable-store.
Sounds good. If you want to chat about it at all before you put in the time I'm happy to do that here. This is one of those projects where I don't plan to add much more feature-wise (as mentioned) just to keep things simple. But, I'm always open to hearing about new ideas. :-)
from observable-store.
I don't appear to be getting message notifications from github, so afraid I've only just now seen your message. In fact, I've already made a new feature branch and have put the code on it and its fully ready. I have been trying to push to your repository but it is not allowing me. Its erroring with:
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/DanWahlin/Observable-Store.git/'
I've changed my password just in case, but its not made any difference. Is there some setting on your repo which is stopping me from pushing a branch to it, or do you need to perhaps add me as a contributor before it will allow me to push the branch?
from observable-store.
I've just read a bit on github, I need to be added to collaborators to be able to push a branch to the repo.
from observable-store.
Hi Mickey. I wouldn't want a new branch showing up actually. I'm OK with looking at a pull request though.
from observable-store.
Hi Dan, Sorry I haven't contributed for some time now and am forgetting the approach. Should I create and push to my own repo and then do a pull request from there?
from observable-store.
Once you've cloned it you can work locally and then submit a pull request back to this repository. Here's a post that shows several options:
https://www.digitalocean.com/community/tutorials/how-to-create-a-pull-request-on-github
But, before you go to the trouble to do that, let me know what you're planning. I don't want you to go to the trouble to do it only to later tell you, "Thanks - but not interested in that". I'm definitely interested in hearing about it first if possible. I'm just not looking to expand this particular repository much as mentioned and want to respect your time as well.
from observable-store.
Totally understand, and thanks. However I've already fully coded it up, and also updated the readme. So the most efficient would now be to simply create the pull request. then you could have a look. And if you feel its not for you, then its totally fine, no issues whatsoever. However as I am planning on using it for myself at work, and I wanted this, I thought I should share it too and give something back to the community too. :)
from observable-store.
Sounds great! Looking forward to seeing it.
from observable-store.
Thanks, I've just created the pull request. Looking forward to hearing what you think of it.
from observable-store.
Awesome - thanks. Just read the general idea and I really like it. I'll have to spend more time on it when I can though and make sure it doesn't impact the existing API at all. Slammed with a project right now but once I come up for air I'll take a closer look. Thanks again!
Update:
Just realized this is a global selector - awesome! Been wanting that actually for cases where people need anything/everything. Haven't looked at the code yet but does it impact the API at all aside from adding the new setting? Sounds like it doesn't impact anything....I'll take a look as soon as I can. I'm going to be sending out a new blog post about it actually - would love to get your feedback if you're up for it since you're using it (and contributing :-)).
from observable-store.
Thank you so much for accepting the pull request, and thank you too for your kind words in the version history. Much appreciated!
Yes, I did it so that its completely backwards compatible. Speaking personally, I would really not be amused if anyone put in a breaking change, so that was super important to me.
I'll be very pleased to feedback on a blog post, and will watch out for a tweet on it. I've used Redux previously and so can add my perspective from that too.
from observable-store.
Here's the post I mentioned:
https://blog.codewithdan.com/simplifying-front-end-state-management-with-observable-store/
I'm being careful not to call out a specific pattern in the post since every scenario is different (and we all have a million viewpoints on state management). But, if you have time to add a comment at the bottom about your experience with various options that'd be awesome!
from observable-store.
Thanks I'll certainly have a look at the blog post and will definitely add a comment.
Thanks for spotting and fixing the property name in settingsDefaults. I first went with underscores in the property name in the interface, and then later thought it needs to be camel cased, and did a variable name change in the interface using the IDE, which of course missed the property in the settingsDefaults, so thanks again for fixing that.
from observable-store.
Appreciate it - thanks Mickey! And...I realized I spelled your name wrong in the readme (left out the "e"). Sorry about that - fixed now.
from observable-store.
Related Issues (20)
- Replay Subject for edge cases HOT 4
- Why won't a getter from a service/state work after any store changes? HOT 6
- Missing properties after setting state HOT 8
- Weird store structure when using stateSliceSelector HOT 2
- Store structure: Flat vs Complex + stateWithPropertyChanges returns function if that's what was passed in the setState HOT 1
- This lib can be performance problems HOT 1
- It would help so much if you included a fully working react example HOT 2
- Using state in synchronous manner HOT 1
- SetState method is not working HOT 9
- Rx.js 7.2 migration and compatibility? HOT 4
- Using JSONPath and Observable store HOT 4
- Setting State via SetState for one property HOT 4
- CommonJS or AMD dependencies can cause optimization bailouts. HOT 3
- How can I access the Observable-store data through the `window` object? HOT 3
- Is it necessary to deep clone the state when dispatching? HOT 7
- Problem with ReduxDevToolsExtension under electron environment HOT 5
- Losing Class (getters/setters) when returning object from store HOT 1
- setState() does not update property when setting to undefined HOT 1
- How to store n number of propertes (making the state properties dynamic) HOT 1
- is it possible to filter by Action? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from observable-store.