Closed seijikun closed 3 years ago
Sorry, I missed this issue. Yes, those should probably be set to protected, though they aren't the preferred way to add lifecycle hooks. They recent got added to the typings, so before they were not part of the interface. I think you can set a less restrictive access modifier on a child class, so protected shouldn't affect anything that is already declared public, but I might be thinking of any number of other languages here.
I think you can set a less restrictive access modifier on a child class, so protected shouldn't affect anything that is already declared public, but I might be thinking of any number of other languages here.
I'm afraid I don't completely get what you mean by that. Isn't that exactly what I did?
MyComponent
being a child class of Ractive
and using protected
on the onrender()
method, instead of public
, like in the parent class. This causes a compile error.
Or did you mean a change needed in Ractive itself?
I mean, if we change the ractive typings to have lifecycle methods be protected, it wouldn't stop someone from exposing them if they wanted to? I don't think they were intended to be exposed as methods at all, so it probably wouldn't be awful to restrict them. It only really makes sense to set them in the init options if you're not using a class anyways.
Ah, yes. That makes sense. Relaxing the access specifiers in a child class seems to work. demo
Once travis finishes travising, the lifecycle methods should be protected on edge.
Thanks! No compile errors left ;)
Description:
When using Ractive with Typescript: Since Version
1.4.0-build-56
, the lifecycle event methods such asonrender()
,oncomplete()
,onconfig()
,onunrender()
... have to be public in subclasses of Ractive, otherwise the project will not compile. Was this change on purpose?Versions affected:
Reproduction:
Before:
this now fails with:
to fix it, the
protected
access specifier has to be relaxed topublic
. To me, this does not seem right, since that event method now is part of Ractive's public API, and can be called from outside (users of a Component or Ractive instance).