Skip to content

Statics #146

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

Merged
merged 7 commits into from
Oct 26, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,10 @@ export function componentFactory (
const Super = superProto instanceof Vue
? superProto.constructor as VueClass
: Vue
return Super.extend(options)
const rv = Super.extend(options);

for(let sttc in Component)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add curly braces for for and if expressions?

if(!(sttc in function() {}) && Component.hasOwnProperty(sttc))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if hasOwnProperty will impact component inheritance. A test case should be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Written like that, a child class doesn't forward the statics of its parent. hasOwnProperty means the the property is in the object, not its prototype.

I am not sure of the question, therefore I don't know if it answers - what do you mean by "impact component inheritance" ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider

@Compoent class Parent extends Vue { static config = {} }
@Compoent class Child extends Parent {}

Child.config // expect an object {}

Written like that, a child class doesn't forward the statics of its parent.

I think you already understand me. And I even suspect whether we should support inheritance any way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, Child.config would, in this implementation, retrieve undefined
Beside beeing the easiest to implement, I just checked on how typescript managed static' legacy, and it seems coherent with the usual behaviour.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it simple. vue-class-component is for both Babel and TS users. Rolling out a babel compatible version might be challenging.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, is it still a "change requested" or an acceptation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!(sttc in function() {})

Is this necessary? Looks like only using hasOwnProperty is enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will for instance avoid statics to override name or apply

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why shouldn't they be overridden? Is that stated in the spec?
I think we should follow the es spec as possible since the user would expect it.

rv[sttc] = Component[sttc];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename rv to Extended and also sttc to key? I cannot see what the current name means...

return rv;
}
10 changes: 10 additions & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,14 @@ describe('vue-class-component', () => {
expect(parent.value).to.equal('parent')
expect(child.value).to.equal('child')
})

it('forwardStatics', function () {
debugger;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

@Component
class MyComp extends Vue {
static myValue = 52
}

expect(MyComp.myValue).to.equal(52);
})
})