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.

Why won't a getter from a service/state work after any store changes?

See original GitHub issue

Hi there,

Just to clarify my understanding:

If you read: #using-observable-store-with-angular => Point 9, it says the following:

// Can call service/store to get data directly 
// It won't fire when the store state changes though in this case
//this.storeSub = this.customersService.get().subscribe(custs => this.customers = custs);

I find that the following is indeed not working:

public getIsLoggedIn(): Observable<boolean> {
    return this.stateChanged.pipe(switchMap((x) => of(x.isAuthenticated)));

Why isn’t it the case that when you call a get wrapper function that it won’t fire any subsequent, or even initial/last state changes?

Also here: #comment @DanWahlin says the following:

… Currently the store will send the latest state so I wanted to check on that part of your scenario there.

I’m thinking i’m missing some big part of the puzzle but I haven’t been able to figure it out.

Thank you for any answers!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

JasonLandbridgecommented, Feb 11, 2021

@spierala, thanks for the answer!

I managed to solve it but the problem was unrelated to Observable Store.

I was making separate service classes, and some service classes had a dependency on others. My mistake was putting all those subscriptions in the constructor of each service class, which meant some subscriptions weren’t even setup to begin with.

I solved this by giving each service class a setup() function and then call each ‘service.setup()’ on app startup.

Now everything works as perfectly!

Stupid mistake on my part.

DanWahlincommented, Feb 11, 2021

I’m catching up on the thread (thanks for jumping in @spierala - appreciate that) but am glad you found the root of the problem @JasonLandbridge. I do something similar in my services where I need to initialize something. I call it init but it’s basically the same purpose as your setup call.

As far as the “stupid mistake on my part” comment, I can sympathize. I’ve made plenty of those mistakes myself. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getters is not working and state value cannot be change in ...
$store.getters.semuaJasa , once I change the code using getters, it won't display in the browser. I can't change the value ...
Read more >
Service Plugin - feathersjs-ecosystem/feathers-vuex
The makeServicePlugin method creates a vuex plugin which connects a Feathers service to the Vuex store. Once you create a plugin, you must...
Read more >
Angular Service: State Management | Tutorial | Nisan Sabag
To keep track of the changes for this property, we will bound it to template of the component that use it with a...
Read more >
Service Module API | FeathersVuex
The Service Module creates plugins which can be used to connect a Feathers service to the Vuex store. Once you create the plugin,...
Read more >
Need more info regarding release update 'Validate Getter ...
For most subscribers, I suspect that no changes will be necessary. ... continue to work for their subscribers after the update is enabled....
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 Post

No results found

github_iconTop Related Hashnode Post

No results found