-
-
Notifications
You must be signed in to change notification settings - Fork 407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Create attrTypes to describe the interface of a component #35
RFC: Create attrTypes to describe the interface of a component #35
Conversation
I like this. It can land after 2.0 and I'm interested to see a PR after glimmer lands. |
Shouldn't it be |
Yes. Still not a fan of it though. A list of allowed attributes is not very expressive. I prefer React's approach which lets you specify further constraints. |
@mmun I wanted to put in types however I didn't want the change to be too big initially without there being an interest for it. The other thing is I was considering using the Ember data attribute types for declaring the data types, what do you think. The only other alternative I can see would be using I like the react way of doing things. @locks I did have originally two separate interfaces, where by you could specify the inbound attributes and the outbound properties. I think the outbound component to the components template is more important however attributes would probably chime more into glimmer I suspect. |
@mmun an alternative to the two separate interfaces would be having the ability to specify an attribute/property as private/protected. My only worry with this is it is getting complex enough that I would personally prefer the computed property work to be expressed within this data structure.
|
@jonathanKingston I don't think it should be expressed as a CP. I was thinking of putting it on attrTypes, not unlike React. Something like import { attrType } from "ember-component";
return Ember.Component.extend({
attrTypes: {
checked: attrType({ boolean: true })
}
}); |
@mmun I think there are two use cases here if both are important is a different story. Template usage:
my-component.js
my-component.hbs
The ability to accept attributes and what gets exposed are distinct, I don't thing exposedProperties would need types as they come from the JavaScript internals. The only other alternative is the parity with ember data which would cater for both use cases. |
+1 for |
Working on the change now. |
@jonathanKingston might wanna wait until after glimmer lands because it will massive simplify how attributes are propagated through a template. |
@mmun I was just writing up the changes that were discussed here, no real effort being expended: I will look over the latest changes there and see how that impacts this. |
@mmun one other thing that I have been toying with is the fact that it is very hard to get multiple properties into a component, much like you can for the This could be resolved with this issue in several ways, however here is the most in keeping that I can think of right now: Add in a serializedArray type to deserialize the type into an array:
The serializeArray would work similar to In the component:
|
I forgot to update this to mention that @mixonic resolved my last comment in: An attribute type would still be required for this data type however. |
👍 on more complex validators. |
We would like to explore using JavaScript typesystems (e.g. TypeScript, Flow) rather than adding our own ad-hoc component type checking at runtime. If we do end up doing runtime type checks, we would like to explore using decorator syntax rather than To move this forward, we would like to see it implemented as an addon that can be vetted in the community before it is supported in core. |
@tomdale thank you for reviewing this also. I wasn't sure if that would be a direction that would be adopted by ECMA so I assumed that would be a no-go. The decorators solution certainly seems a viable option certainly. Is this the direction Ember Data is going to take also? |
...nent
Rendered