Closed alexdiliberto closed 6 years ago
@alexdiliberto within the hooks, we should only call super.didReceiveAttrs
if we know the parent calls has that same hook defined. Otherwise, calling super.didReceiveAttrs(...arguments);
will error.
I think that may be part of the application refactoring needs, not necessarily an Ember bug.
That is how JavaScript works...
class Greet { constructor(msg) { this.msg = msg; } hello() { console.log(this.msg)} }
let g = new Greet('hi')
g.msg
"hi"
g.hello()
VM586:1 hi
class Yo extends Greet { hello() { console.log('Yo') }}
let y = new Yo('sup')
y.msg
"sup"
y.hello()
VM699:1 Yo
class Sup extends Yo { hello() { super.hello(); console.log('sup') }}
let s = new Sup()
s = new Sup('dog')
s.msg
"dog"
s.hello()
VM699:1 Yo
VM866:1 sup
class WhatUp extends Sup { yo() { super.yo(); console.log('what up ' + this.msg) }}
let w = new WhatUp('peeps')
w.msg
"peeps"
w.hello()
VM699:1 Yo
VM866:1 sup
w.yo()
VM1115:1 Uncaught TypeError: (intermediate value).yo is not a function
at WhatUp.yo (<anonymous>:1:44)
at <anonymous>:1:3
If @rwjblue thinks this is a bug in Ember then we'd need to change the Component hooks to define the methods as noop functions. I'm not sure why that is not the case now. See https://github.com/emberjs/ember.js/blob/v3.5.0/packages/ember-glimmer/lib/component.ts#L737-L745
So this would be a change request to the Component. Not a bug in Ember. Do the guides as of v3.5 suggest we use class
syntax yet?
Ya, I think we should ensure that all of the component hooks are defined on the base class. It’s actually important unrelated to using native classes (it helps ensure consistent shapes and whatnot)...
@rwjblue if that's the case we should probably try to get this into 3.6, no? I'll submit a PR asap
Converting an app over to use native classes and noticed some component hooks throw errors when calling their superclass equivalent hook.
didReceiveAttrs
is an example of one hook which will error@rwjblue helped answer my question today on Discord