简体   繁体   中英

Does aurelia use custom binding behaviour classes as singletons?

I seem to have an odd error, and I am not sure if it is my assumption which is incorrect here or not, but there is no docs on the subject.

So when you make custom elements/attributes and you set members on that class, they are per use, so every usage of these custom attr/elements would have their own instance of the class to go with it.

However it currently seems that when using binding behaviours the class is shared between all uses of that binding behaviour, with the bind method being the point of isolation.

I say this because I was assuming they were all setup to be an instance per use and in this case some async logic is getting a value from the last used binding behaviour on the class ie this.someClassStateVar .

So can anyone confirm if Aurelia uses binding behaviours in a singleton scope?

=== Edit ===

Based upon first answer I wanted to confirm scenario:

<section with-binding.bind="something">
    <input value.bind="somethingElse & someBindingBehaviour">
    <input value.bind="somethingElse2 & someBindingBehaviour">
</section>

So I was expecting that there would be 2 instances of someBindingBehaviour class and each would be applicable to the relevant input, but the behaviour I am seeing is that they both use the same instance of the someBindingBehaviour class.

In Aurelia, value converters and binding behaviors are singletons. They should be stateless. Some types of binding behaviors may need to keep track of some state, the best place to store that state is on the binding instance (passed to the binding behavior's bind and unbind methods).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM