-
Notifications
You must be signed in to change notification settings - Fork 5
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
Should components define their 'arguments'? #18
Comments
In the spirit of a couple of weeks project. Since it should be easily ignored by implementation, let’s make it a comment inside the component definition, first comment node inside a template. Kind of a python docstring. Then if template engine support it it will generate validation code for the context data. Do you have syntax in mind ? |
Using a comment to annotate components like Python docstrings is an interesting idea, hadn't thought of that. I was assuming we'd use some attribute on the
...which in that case would mean |
Using only a tag attribute limit your power of expression.
For exemple you can’t define if name is a string or an array
Doesn’t mean that we have to use all the freedom we have but let’s keep the options open
Benjamin Dreux
… Le 5 févr. 2018 à 06:20, Caolan McMahon ***@***.***> a écrit :
Using a comment to annotate components like Python docstrings is an interesting idea, hadn't thought of that. I was assuming we'd use some attribute on the <template> tag, something like:
<template data-tagname="my-component" data-required="name amount type">
...which in that case would mean <my-component> expects to at least have name, amount and type attributes.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Comments would be more flexible. However, we wouldn't be able to provide type warnings at template compile time anyway (as we won't know the type of the data until runtime). Since I'd like us to avoid runtime errors in the templating language (but give as many useful compile-time errors as possible), I don't think we'd gain much from the extra flexibility. Parsing HTML comments as something like JSDoc would also require an additional parser (assuming it's more detailed than the attribute example I gave). This would complicate implementations a bit. Which may not be a huge problem server-side, but could bloat the client-side library. On the positive side you could add more detailed descriptions for each expected attribute when using HTML comments. Though I suppose there's nothing stopping you from doing that now. |
As i see it, the context expectation should be optional.
At writing time, you can choose to write down thoses expectations. As a reference we could check out: https://reactjs.org/docs/typechecking-with-proptypes.html In the server side, as you said, nobody care if the module is bigger. On my app what i'd like to type/check is for exemple: Keeping thoses expectation next to the template and close to to the template would help in keep the state of the app in a clean state. |
I like to think of components as functions accepting named arguments (e.g.
title="{{ article.title }}"
). Should the<template data-tagname="my-template">
tag also require/allow you to define the context it expects to receive?The text was updated successfully, but these errors were encountered: