-
Notifications
You must be signed in to change notification settings - Fork 12
[WIP] Flesh out Component/Route/Controller typings #24
Conversation
types/ember/index.d.ts
Outdated
@@ -1538,6 +1684,7 @@ namespace Ember { | |||
*/ | |||
has(name: string): boolean; | |||
} | |||
const Route: Mixin<Route>; |
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.
Route
should still be a class, shouldn't it?
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.
Sorry - didn't mean to include that, though I think I'll need to make some changes.
const component1 = Component.extend({ | ||
actions: { | ||
hello(name: string) { | ||
console.log('Hello', name); |
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.
It would be nice to test that the context gets set properly, e.g. by calling this.get('someComponentProperty')
types/ember/index.d.ts
Outdated
**/ | ||
actions: ActionsHash; | ||
} | ||
const ActionHandler: ActionHandler; |
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.
I think this should be Mixin<ActionHandler>
} | ||
const ActionSupport: ActionSupport; | ||
|
||
interface ClassNamesSupport { |
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.
Where does ClassNamesSupport
and ActionSupport
come from?
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.
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.
Oh, ok, I was testing on ember 2.9, those must have been introduced later.
I need to grab the TemplateFactory type off of the htmlbars-inline-precompile module for the layout type in the Component class. There's a PR in for grabbing types from function return values, but I'm not otherwise seeing a good way to do it without declaring a dummy type or just re-declaring the interface in the Ember module. Thoughts? |
You should be able to import { TemplateFactory } from 'htmlbars-inline-precompile'; |
4084edf
to
975f973
Compare
I'm getting failing tests from ember-inflector and qunit. Happy to fix them up, but they're way outside of my already over-sized scope here. Suggestions? |
types/ember/index.d.ts
Outdated
} | ||
const ControllerMixin: Ember.Mixin<ControllerMixin>; | ||
|
||
namespace Ember { |
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.
@theroncross The tests pass locally for me if you change this line back to export namespace Ember
and revert the ember-inflector tests changes in 5356bd0
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.
Got it. I'm still getting Cannot find name..
s in the ember-qunit
declarations for Hooks, Assert, and Qunit. I've diffed everything I can think of to see if I've accidentally changed something. Where are those declared?
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.
What code are you referring to?
@dwickern I see that you added a static property to the Component class. Could you explain why? |
It's public API: Component.positionalParams |
5356bd0
to
b23ef2c
Compare
- [x] Add Component class properties, methods, and events - [x] Refactor CoreView to be a private class with correct extends - [x] Move private Component 'uses' outside exported namespace - [x] (Unfortunately) had to move Controller pieces, too. - [x] Add Component tests and comments from Ember API docs
The Controller and Route classes don't seem to be exporting all their members in the way the Controller is, but I'm lacking the bandwidth to spot the problem.
sendAction(action: string, context: any): void; | ||
targetObject: Controller; | ||
static positionalParams: string | string[]; | ||
class Component extends CoreView.extend(ViewMixin, ActionSupport, ClassNamesSupport) { |
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 there be support for dynamic/runtime keys on the component? There will obviously be a loss of type-safety since they will be typed as {[key: string]: any}
or is the mandate that key's be static with a default value? I feel like the former is more in line with how Ember works {{my-component dynamicPropKey=anyValue}}
, but I think I might prefer the latter because of type-checking...
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.
Yeah, if you add the looser type you lose all help from the compiler for get
and so on, alas.
For TS to be useful people will need to declare what the component expects as its API in the class definition for it, because while you can set arbitrary keys on a component invocation, they’re essentially meaningless: nothing will ever be done with them.
For cases where people want to support adding arbitrary values at a given key, they can type that key as variousData: any
in the component declaration and then it’ll be available within the component methods.
b23ef2c
to
a9677ce
Compare
|
You're exporting it as LGTM |
I was thinking specifically of the case in the component tests where I have to import the whole module to access |
SHIP IIIIIT! |
I suppose we could have a named export too. I don't want to do anything crazy, |
Thanks for solving the merge conflicts @theroncross ! |
extends
anduses
sections from the 2.14 api docs for structure:became
class Component extends CoreView.extend(ViewMixin, ActionSupport, ClassNamesSupport) {...}
Note - api labeled private has not been included, but that includes
TargetActionSupport#triggerAction
which doesn't really seem private so much as 'not recommended'. 🤷♂️const ActionHandler: Ember.Mixin<ActionHandler>
) where needed.