-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Labels
Description
I am not yet completely sure how I would implement this, but I am thinking of doing some backwards incompatible changes to Blaze Components. In short, it is getting rid of a data context, instead of replacing it with scope.
- including
{{> Component}}would not pass data context anymore, scope of the included component would be empty - you can include only with explicit keyword arguments like
{{> Component header=value}}.headerbecomes a reactive value (populated fromvalue) inside the scope of theComponent. - components have a known list of arguments they can get, with additional metadata:
- is argument required
- documentation of the argument
- equality function of those arguments
- we will not check the type/value of the argument, because I do not want to force evaluation if not necessary (so if
valueis a function, and you pass it on, it would be great that it is passed on as a function) - arguments can be marked as constructor-level argument, or render-level argument (are they passed when component instance is created, or are they available once it is rendered)
- other arguments than those specified passed make rendering fail
- each argument is exposed as a method on the component
- components can then have public methods which can be called from outside, so you can also pass a component itself to child component, like
{{> Component parent=this}}, and then code inside could run something likethis.parent().fooBar()iffooBaris a method of the parent component thisinside a template would be now the component instance itselfparentComponentand things like that would not be available anymore, component should get parent component explicitly as an argument, if it depends on it- not sure about children components?
- we will have to have some way to mark public methods, because I do not want to have many private methods which I would then have to use in templates like
{{_privateHelper}}, or should we do this? - to me there are two levels of private methods: some which are private to component logic and should not be called from a template (I use
_prefix on them), and some which are private to templates, and should not be called from outside
- for helpers/methods you can still mix args and kwargs
- kwargs object at the end will be passed only if it there are really kwargs provided
- there will be no
hashthere, it will just be an instance of known class - functions passed to helpers will not be automatically called, but if you use it in a template it will be (so
{{value}}will callvalue()for you ifvalueis a function, but{{fooBar value}}will get you a functionvalueas the first argument, ifvalueis a function)
What my plan is that I bump this package to 1.0 and release it. And then the above changes will be 2.0 of this package.
So the API of a component are arguments you can pass, and public methods you can call on the component. Events handlers are internal to the component.
cc @stubailo, because I think he will like some ideas here