antonmedv / monkberry

Monkberry is a JavaScript library for building web user interfaces
https://monkberry.js.org
MIT License
1.49k stars 78 forks source link

stateless directive #24

Open francescoagati opened 8 years ago

francescoagati commented 8 years ago

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;
  }
}
antonmedv commented 8 years ago

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.

francescoagati commented 8 years ago

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

francescoagati commented 8 years ago

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

francescoagati commented 8 years ago

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