Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

Custom toString() is skipped by the factory #81

Closed
lzhoucs opened this issue Oct 12, 2016 · 1 comment
Closed

Custom toString() is skipped by the factory #81

lzhoucs opened this issue Oct 12, 2016 · 1 comment
Assignees
Milestone

Comments

@lzhoucs
Copy link
Contributor

lzhoucs commented Oct 12, 2016

Package Version: "2.0.0-beta.13"

Code

interface Foo {
    fooProp: string;
    toString(): string;
}
const fooFactory = compose<Foo, any>({
    fooProp: 'A Foo',
    toString: function(this: Foo) {
        return `[this.fooProp]`;
    }
});
const foo = fooFactory();
assert.strictEqual(foo.toString(), '[A Foo]');

Expected behavior:
The foo.toString() in example code above is expected to return [A Foo], which has been the the case until recently #65 is merged. L107 seems to intentionally skip toString that is defined in the prototype and a toString defined by the library in L58 is used in the factory.

Actual behavior:
foo.toString() returns [object Compose]

Currently a few places in the stores are relying on a custom toString to work properly. I can understand the intention of #65/#63, however I wonder if it makes sense to have the toString (if defined in the prototype) override the default one defined by the library?

@kitsonk
Copy link
Member

kitsonk commented Oct 17, 2016

Good catch. Yes, with the addition of the diagnostic information, we started skipping that property, because it shouldn't be mixed, but of course if it is part of the provided prototype, it should be. I agree, we should allow it to be mixed in, if it is explicitly passed. I think we will have to modify the mixin process to allow the calling APIs to specify if the method should be overwritten or not.

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

No branches or pull requests

3 participants