aurelia / templating-binding

An implementation of the templating engine's Binding Language abstraction which uses a pluggable command syntax.
MIT License
32 stars 26 forks source link

@signaledFrom decorator? #92

Closed dkent600 closed 6 years ago

dkent600 commented 8 years ago

Could we have a new decorator like @computedFrom, but one that indicates that a computed property so decorated should be re-evaluated upon receipt of a signal?

Something like:

@signaledFrom("mySignalKey1", "mySignalKey2")

This would help, for example, in a use case where I have a property whose value is computed from a property on each of many objects in an array of objects.

I know there has been a suggestion to base such a computed property on a backing property, and decorate the computed property as @computedFrom('myBackingProperty'), but that seems to me like a hack.

dweber019 commented 7 years ago

@dkent600 I suggest using a getter function with oneTime binding to stop dirty checking and add a signal behavior.

The getter function

class Test {
  get signalerProperty() {
    console.log('signaler triggered', new Date());
    return new Date();
  }
}

Binding options

<p>${ signalerProperty & oneTime & signal:'mySignalKey1' }</p>
<div innerhtml.one-time="signalerProperty & signal:'mySignalKey1'"></div>
Alexander-Taran commented 6 years ago

well technically it would not be pure computational dependency. since you will have to signal.. something. like in call a method.. and a good way would be to have a plain property and a function for computation and instead of signal, you could just call that function

@signalable get blah() {
   painful computation..
}

someOtherFunction() {

heavy changes to arrays and the world itself
signalSomething()
}

becomes

blah

computeBlah(){
   painful computation..
}

someOtherFunction() {

heavy changes to arrays and the world itself
computeBlah()
}

why travel to space and back with signaling?

could be closed