antonmedv/monkberry

stateless directive

francescoagati opened this issue · 4 comments

Hi,
this is a proposal for using a static directive. actually every time a directive is used, an object is created.
My idea is:
if in the directive function is passed a function instead an object, the function is called with node element.

example

directives: {
  background:functon(node,value) {
       node.style.backgroundColor = value;
  }
}

Hi,
Yes, this is good solution. I'll try to implement it. But in this case we need to add if for each directive call. Maybe it will be better to use another syntax for stateless directive like @bg={{ }}. But it will complicate learning.

Or using ::bg=
The simbol :: Is used in many lang for static methods and properties access

Another syntax is better for performance instead of using if at runtime

i think we can pass also state in staless directive

directives: {
  background:functon(node,state,value) {
       node.style.backgroundColor = value;
  }
}

where state can be bind,unbind,update