-
Notifications
You must be signed in to change notification settings - Fork 16
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 generally looks good. Only thing I would say is it seems weird for owner
to come second, I imagine it'll probably be first in general with framework objects in the future, but I can also understand why you'd want to do this without making breaking changes.
Totally agree. My thought was to force it to be two args first, then swap them in a public API in a major version bump. Which should be easier... |
Ensure that services and other injected things work properly from the constructor.
4201039
to
87ab826
Compare
I just had an idea, which might be really stupid, but I would like your opinion on it. What if, instead of passing Since export const __OWNER_REFERENCE: { owner?: ApplicationInstance } = Object.create(null);
export default class SparklesComponentManager {
// ..
createComponent(Klass: typeof SparklesComponent, args: ComponentManagerArgs): CreateComponentResult {
__OWNER_REFERENCE.owner = this.owner;
let instance = new Klass(args.named);
__OWNER_REFERENCE.owner = undefined;
return instance as CreateComponentResult;
}
// ...
} import { setComponentManager } from '@ember/component';
import { setOwner } from '@ember/application';
import { __OWNER_REFERENCE } from 'sparkles-component/component-managers/sparkles';
class SparklesComponent<T = object> {
constructor(public args: T) {
if (__OWNER_REFERENCE.owner) {
setOwner(this, __OWNER_REFERENCE.owner);
}
}
// ...
} |
Yep, definitely would work. I'm mostly trying to match the API of the upcoming glimmer component RFC, which currently has two args (owner and args). I'll cross link the RFC once its officially submitted (hopefully in the next day or so). |
Is there anything holding this back? Can I help? |
We decided to focus on GlimmerComponent implementation, since this would either not match the API, or be a breaking change |
|
||
class SparklesComponent<T = object> { | ||
constructor(public args: T) {} | ||
constructor(public args: T, owner: any | undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is swapped now I believe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be
constructor(public args: T, owner: any | undefined) { | |
constructor(public args: T, owner?: {}) { |
to describe the following constraints:
(a) undefined
need not be passed explicitly under any circumstances
(b) if an argument is passed, it cannot be null
or undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mike-north - Seems good, should I use object
or {}
? (mostly just curious to the reasoning)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let x: object = ''; // ❌
let x: {} = ''; // ✅
If you want to allow string
, number
Symbol
and boolean
, use {}
If you just want things that are assignable to JS Objects
, use object
See #33, closing in favor of using |
Ensure that services and other injected things work properly from the constructor.