Closed liamzdenek closed 6 years ago
@liamzdenek ... Thanks for your suggestion.
As a general rule, I believe that createXyz()
implies an object creation, so this
would be immediately available.
That being said, the Feature
/Aspect
objects are simple object literals ... merely containers of content that is consumed by launchApp()
.
As mentioned in the docs here (see "Aspect State Retention"), Aspect
hooks are actually invoked as methods, so the this
binding is available, should the developer choose to use it. That being said, I did not want to make that a requirement. In other words, functional closures could be used for state retention as well.
This seems a bit different than the react transition from createClass()
to React.Component
derivations. Even that has been further refined to include simple functions (i.e. stateless components). In general functional components are preferred, although classes provide some additional life-cycle methods.
In my opinion, full blown classes with prototypical inheritance is a bit of an overkill in this use case. We are simply providing a structure for content to be consumed by a function (i.e. launchApp()
).
Thoughts?
Working as designed ... see explanation (above).
React made a similar transition, see here[1].
It would also resolve some early confusion that I initially had around whether Aspects/Features are purely functional, or are stateful. I wasn't sure when exactly
this
began to exist, and in what lifecycle methods it was available. The use ofthis
leans towards being stateful, and I believe explicitly using Classes would make this clearer.This would mean renaming the genesis function to constructor, which would be a breaking change. Name could be transitioned to a static property.
[1] https://toddmotto.com/react-create-class-versus-component/