lega911 / angular-light

Alight is a library for building interactive MVVM web interfaces/applications. (project is deprecated)
MIT License
274 stars 43 forks source link

Unique directives for each ChangeDetector #248

Closed Ni55aN closed 7 years ago

Ni55aN commented 7 years ago

I use version 0.14. It does not work $ns, and I can not use direct directives either, because the symbol "!" is not allowed at the end of tag name (Pug simply uses it for its own purposes and trims it).

I make the binding as follows:

function createInstance(){
var mydata = ...
var cd = alight.ChangeDetector();

 /// ...
alight.directives.al.node = function(...){
  // here I need to use "mydata",  but when creating a new instance, the directives are overridden
}

alight.bind(cd, el);
}

For each bind() there must be directives with unique data (in my case I pass this) How can I pass in the directives unique data used by different bind()?

Ni55aN commented 7 years ago

Using &attributes({'node!':''}) added attributes for direct directives, but got another problem: the error Directive not found: node! occurs if one of the variables in the template matches the name of the directive

<div al-repeat='node in editor.nodes'>
<a node!></a>
</div>

Of course I can rename directives, but it would be better to have a more obvious solution

lega911 commented 7 years ago

$ns was deprecated in 0.14 alight.directives is place for "global" directives per alight (per instance).

I didn't get what exactly you try to do, so I made a few examples: https://jsfiddle.net/myo7aa6q/ - the same directive, but different data for different elements https://jsfiddle.net/hj6sa0et/ - different data with own directives inside https://jsfiddle.net/9Lajz39g/ - clones of alight https://jsfiddle.net/j5pr2dy6/ - one of the way to change syntax ( changed directive! -> @@@directive )

Ni55aN commented 7 years ago

@lega911 tranks, but how to use ChangeDetector with alight() ? I need to call scan() from outside

lega911 commented 7 years ago

var changeDetector = alight(element, data);

lega911 commented 7 years ago

or https://jsfiddle.net/tozxLpc6/

Ni55aN commented 7 years ago

Thank you!