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.

Polymer-redux 1.0 + Polymer 2 hybrid mode doesn't expose state + dispatch is unknown

See original GitHub issue

It would be great if Polymer-redux would work not only with pure Polymer 2 (e.g. ES6 class syntax) but also with Polymer hybrid mode.

Right now, for hybrid element with the PolymerRedux behavior the Redux state isn’t available and calling this.dispatch causes the following error:

Uncaught TypeError: this.dispatch is not a function

This issue can be replicated by running demo/ready-state.html after applying PR https://github.com/tur-nr/polymer-redux/pull/86.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
kevinpschaafcommented, Aug 26, 2017

So if I understand, in v1.0.0 PolymerRedux changed from being a behavior (object) to a mixin (function). There’s not a straightforward way to safely auto-convert mixins back to behaviors due to the way super works in ES6 (i.e., we can provide Polymer.mixinBehaviors(), but not Polymer.makeBehaviorFromMixin()).

That said, with the current construction of the PolymerRedux mixin, it looks possible to do it manually, if that’s a solution for you. I did a proof of concept here: https://glitch.com/edit/#!/brick-raver?path=public/index.html:43:2

Basically, this code adds back the behavior-based interface to the mixin function, such that it can be used as a mixin on classes OR a behavior object in hybrid elements.

  const MixinFactory = PolymerRedux;
  PolymerRedux = store => {
    let curr;
    const mixin = MixinFactory(store);
    const base = mixin(class {
      constructor() { return curr; }
      connectedCallback() {}
      disconnectedCakkback() {}
    });
    const behavior = {
      created() {
        curr = this;
        new base();
        curr = null;
      },
      attached: base.prototype.connectedCallback,
      detached: base.prototype.disconnectedCallback,
      dispatch: base.prototype.dispatch,
      getState: base.prototype.getState,
      registered() {
        this.constructor.actions = this.actions;
      }
    };
    return Object.assign(mixin, behavior);
  }
  ...
  // Can be used as a behavior OR a mixin
  const ReduxMixinOrBehavior = PolymerRedux(store);

It’s a bit brittle/hacky, but something like this might work as a stop-gap solution for folks here.

Alternatively, @tur-nr could just consider factoring the code in the mixin callbacks out into shared functions and provide an option to return a behavior that uses the shared code, to avoid needing to deal with super issues. We did something like this for MutableData vs. MutableDataBehavior.

0reactions
AliMDcommented, Jan 23, 2018

@kevinpschaaf thank you very much.

@tur-nr could you please add this as a behavior.htm in the project?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · tur-nr/polymer-redux · GitHub
Polymer-redux 1.0 + Polymer 2 hybrid mode doesn't expose state + dispatch is unknown. #87 opened on Jun 13, 2017 by ronnyroeller.
Read more >
Polymer 2.0 upgrade guide
Upgrading a large application that uses many custom, reusable elements. When upgrading individual elements, you can choose to upgrade to either hybrid mode...
Read more >
Documentation - Polymer Redux - GitHub Pages
Bind store state to properties and dispatch actions from within Polymer Elements. Polymer is a modern library for creating Web Components within an...
Read more >
Viewing online file analysis results for 'www.atlanticoline.pt'
Submit malware for free analysis with Falcon Sandbox and Hybrid Analysis technology. Hybrid Analysis develops and licenses analysis tools to fight malware.
Read more >
ECMAScript 6 Tools Awesome - DirDev.com
ECMAScript 6 Tools Awesome. Transpilers. Babel - Turn ES6+ code into vanilla ES5 with no runtime; Traceur compiler - ES6 features > ES5....
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