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.

Fragment state doesn't work when there is a module of the same name

See original GitHub issue

https://gist.github.com/Pyrolistical/882622fe00822418783dc63edcf04bf6

Demo

fragment-state-bug

actions: {
  doubleUsingGlobal(state, actions) {
    return {
      counter: {
        count: 2 * state.counter.count
      }
    }
  },
  // this doesn't work due to module vs fragment conflict
  counter: {
    doubleUsingFragment(state, actions) {
      return {
        count: 2 * state.count
      }
    }
  }
},
modules: {
  counter
}

doubleUsingGlobal breaks the module due to #437, but is unrelated to this issue

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
SkaterDadcommented, Oct 27, 2017

It seems like a good candidate for “dev build” warnings. Conflicting namespaces just need to be avoided, in my opinion.

Does the current documentation make it clear that modules will occupy the namespace you assigned in the larger state/actions trees?

I see no issue with the current behavior, honestly.

0reactions
jorgebucarancommented, Nov 4, 2017

Without a solution for this, there is only one way to monkey patch a module.

doubleUsingGlobal(state, actions) {
  return {
    counter: {
      count: 2 * state.counter.count
    }
  }
}

That will replace the entire counter slice with a new counter object, instead of updating count’s value.

counter: {
  doubleUsingFragment(state, actions) {
    return {
      count: 2 * state.count
    }
  }
}

Now, that will work just as if doubleUsingFragment was an action under the counter slice and update only count.

On the other hand, you still can’t monkey patch an action, as the module’s definition will take precedence, so maybe there is too little gain adding a solution for this.

I am going to close here with wontfix. But I am willing to revisit this in the future if the issue comes up again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dagger 2 on Android: inject same dependency in Activity and ...
To work around this problem, I have to create the FragmentComponent and inject dependencies in MyFragment.onActivityCreated rather than MyFragment.onCreate . On ...
Read more >
Fragment transactions - Android Developers
The fragment remains in the same state ( STOPPED ) as when it is put on the back stack. This means that the...
Read more >
Understanding C++ Modules: Part 3: Linkage and Fragments
External linkage pertains to entities declared extern, functions, class types and their members (including static members), and variables, and ...
Read more >
Creating and Using Fragments | CodePath Android Cliffnotes
A Fragment is a combination of an XML layout file and a java class much like an Activity . Using the support library,...
Read more >
Docs • Svelte
If that's not you (yet), you may prefer to visit the interactive tutorial or the ... don't do this. it will run before...
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