-
-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ValueConverter): enable signal #626
feat(ValueConverter): enable signal #626
Conversation
It would be nice if we could unify this API with the existing binding signaler API. I think there's an opportunity here to tie signaling in at a lower level, in the "connect" phase and refactor the existing signaling logic to leverage the existing binding machinery related to property observation. Today, the ValueConverter expression class looks like this: export class ValueConverter extends Expression {
...
... other methods ...
...
connect(binding, scope) {
let expressions = this.allArgs;
let i = expressions.length;
while (i--) {
expressions[i].connect(binding, scope);
}
}
} I think we could change it to something like this: import { connectBindingToSignal } from './signals';
export class ValueConverter extends Expression {
...
...
...
connect(binding, scope) {
const expressions = this.allArgs;
let i = expressions.length;
while (i--) {
expressions[i].connect(binding, scope);
}
// new stuff:
const signals = binding.lookupFunctions.valueConverters(this.name).signals;
if (signals === undefined) {
return;
}
i = signals.length;
while (i--) {
connectBindingToSignal(binding, signals[i]);
}
}
} aurelia-binding - signals.js (new module) const signals = Object.create(null);
export function connectBindingToSignal(binding, name) {
if (!signals.hasOwnProperty(name)) {
signals[name] = 0;
}
binding.observeProperty(signals, name);
}
export function signalBindings(name) {
if (signals.hasOwnProperty(name)) {
signals[name]++;
}
} Then our BindingSignaler class in templating-binding would reuse the new The signal binding behavior would become much simpler by reusing then new What do you think? |
You meant we determine signals based on |
@jdanyow Things looks a lot neater now. very cool 👍 💯
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests look good, nice work.
src/ast.js
Outdated
return; | ||
} | ||
// support both input type 'signal' & ['signal-1', 'signal-2'] | ||
signals = Array.isArray(signals) ? signals : [signals]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really hot path. Let's remove this line entirely to ensure the connect overhead remains minimal.
I don't think supporting string & array is necessary, just more to document & maintain. If we were to do that here's a good spot to perform the normalization, but again, I would prefer to keep the API surface small and strict:
binding/src/value-converter-resource.js
Lines 15 to 17 in b6565eb
initialize(container, target) { | |
this.instance = container.get(target); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jdanyow All done as suggested. Learnt to be more careful with connect
. About the API, 99% of usage will be a single signal, I do think we need to support normalisation, but I'll let you make the call after this got merged. What do you think ?
@bigopon Would you be willing to PR some documentation for this feature in the value converter doc?
…Sent from my iPhone
On Oct 8, 2017, at 9:01 AM, Jeremy Danyow ***@***.***> wrote:
Merged #626.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Sure i enjoy doing it, and discussing with Jeremy too 😁
…On 9 Oct. 2017 3:30 am, "Rob Eisenberg" ***@***.***> wrote:
@bigopon Would you be willing to PR some documentation for this feature in
the value converter doc?
Sent from my iPhone
> On Oct 8, 2017, at 9:01 AM, Jeremy Danyow ***@***.***>
wrote:
>
> Merged #626.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub, or mute the thread.
>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#626 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AJiBIV8reia9y29UO8qTthL5DJxV46zWks5sqPiigaJpZM4PqJoF>
.
|
This PR:
BindingSignaler
intemplating-resources
, where signaling in there will also trigger here, treating signal universal@jdanyow @EisenbergEffect @thomas-darling @davismj