bind.js
bind.js copied to clipboard
Different transformations per target
Hi, I have a config like this
bind({
date: null,
}, {
date: 'input[name=date],div#display__date',
});
and would like to apply different transformation functions to the input and div. So that the value of the input is still valid, but in the div it gets displayed as a human readable string.
Is this possible with the current implementation?
Edit: I'm currently thinking about adding a third argument to the transform
call "element" that represents the currently targeted DOM Element. That way I can decide how to transform the value. What do you think?
I can't actually remember myself, but what's the value of this
inside your transform function? It might give you what you need (otherwise, I think passing in the element to the transform is a good move).
In my case I'm using arrow functions so this
is undefined or rather the current context. If I use a anonymous function it's an object with the safe
function, so no luck there
Yeah, I just spotted that in the docs (which I should have really known!). I think a PR that has the transform function (and perhaps the other functions) take the current element as the last argument would be perfect.