-
Notifications
You must be signed in to change notification settings - Fork 36
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
Using array-type macros with additional dependent keys? #375
Comments
So It looks like you can abuse the API I made: fruitItems: map('fruits', (fruit) => {
fruit.isSelected = fruit.type === this.get('selectedFruit');
return fruit;
}, 'selectedFruit') If it works though I would not promise it always works, we should make the API official via tests and README, or come up with a real API like the one you suggested. |
@kellyselden Thanks for your quick feedback. I just tried it out the And I agree that it would be great to either have this working with the implicit markup
or a more explicit API as I mentioned earlier. Happy to help with getting the test cases setup for either direction as well. |
It makes sense now. Since array.map((...args) => callback.apply(this, args)) |
@kellyselden That'd be great - I can also work on a PR for altering the array macros that way |
I would love that! If you do that, can you also add a test for each macro you change like this please: test('context is correct', function(assert) {
let callback = sinon.spy();
let { subject } = compute({
computed: map('array', callback),
properties: {
array: [0]
}
});
assert.strictEqual(callback.thisValues[1], subject);
}); |
@kellyselden I'm a bit stuck on how to improve the macros. E.g. for the |
#379 should give you an idea of how to proceed. Let me know if you have any problems. |
Almost a year later, is there a solution? I can imagine something like this: {
foo: "Foo",
bars: ["bar", "Bar", "BAR"],
result: map("bars", "foo", (bar, i, bars, foo) => bar + foo) // => ["barFoo", "BarFoo", "BARFoo"]
} |
The callback passed to The current workaround is the following, which is way more verbose than it should be.
|
I have a case in which I'd like to create a computed property based on an array and another dependent key using the
awesome-macro
formap
. Is it currently possible to let an Array macro not only depend on the target array, but also any other dependent keys, similar to the following?The text was updated successfully, but these errors were encountered: