Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behavior when actions classes extends an reusable abstract class #484

Open
7 tasks
tigredonorte opened this issue Nov 13, 2017 · 1 comment
Open
7 tasks

Comments

@tigredonorte
Copy link

tigredonorte commented Nov 13, 2017

This is a...

  • feature request
  • [ x ] bug report
  • usage question

What toolchain are you using for transpilation/bundling?

  • [ x ] angular/cli
  • Custom @ngTools/webpack
  • Raw ngc
  • SystemJS
  • Rollup
  • Other

Environment

NodeJS Version:6.10.3
Typescript Version:2.3.4
Angular Version:2.4.10
@angular-redux/store version:
@angular/cli version: 1.5.0
OS:windows

Expected Behaviour:

When class A and class C extends B, we expect output in console.log(this.constructor.name) in B class it's always 'A' (if we call a.method()) and 'C' if we call c.method.

Actual Behaviour:

if i call c.method(), it prints "A" (if a and c extends b).

Stack Trace/Error Message:

not necessary

Code

abstract class B{
     public abstract getName();

     @dispatch()
     public doAction(){
          console.log(this.getName(), this.constructor.name);
     }
}

class AAction extends B{
     public getName(){
          return 'FOO';
     }
}

class CAction extends B{
     public getName(){
          return 'Bar';
     }
}

var a = new AAction();
var b = new BAction();
a.doAction(); //it prints correctly "FOO", 'AAction'
b.doAction(); //it prints wrongly "FOO", 'AAction', the correct is "Bar", "BAction"

it only occurs in store folder. It not occurs in others folder..

@e-schultz
Copy link
Member

@tigredonorte looking into this, and was trying to setup a unit test to reproduce the issue - https://github.com/angular-redux/store/pull/487/files

I tried a few combinations:

  • two classes extending from the same abstract class
  • a class extending from another class and overriding getName
  • a class extending from another class and calling super.getName() + returning it's own value

Unless I'm misunderstanding the test case - I was unable to reproduce what you are seeing. Is there any more details that you could provide?

I tend to avoid inheritance in my code so haven't run into this yet, but want to ensure I can meet your use cases also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants