bind.js icon indicating copy to clipboard operation
bind.js copied to clipboard

Different transformations per target

Open maggo opened this issue 7 years ago • 3 comments

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?

maggo avatar Jan 26 '17 14:01 maggo

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).

remy avatar Jan 27 '17 12:01 remy

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

maggo avatar Jan 27 '17 12:01 maggo

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.

remy avatar Jan 27 '17 13:01 remy