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}}. header becomes a reactive value (populated from value) inside the scope of the Component.
- 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
value is 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 like this.parent().fooBar() if fooBar is a method of the parent component
this inside a template would be now the component instance itself
parentComponent and 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
hash there, 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 call value() for you if value is a function, but {{fooBar value}} will get you a function value as the first argument, if value is 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
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.
{{> Component}}would not pass data context anymore, scope of the included component would be empty{{> Component header=value}}.headerbecomes a reactive value (populated fromvalue) inside the scope of theComponent.valueis a function, and you pass it on, it would be great that it is passed on as a function){{> Component parent=this}}, and then code inside could run something likethis.parent().fooBar()iffooBaris a method of the parent componentthisinside 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{{_privateHelper}}, or should we do this?_prefix on them), and some which are private to templates, and should not be called from outsidehashthere, it will just be an instance of known class{{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