-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
Accept an array as valuePath
#456
Comments
I gave this some thought and while I still think that this is a worthwhile feature, implementing it is a bit more complex than I initially expected. There are two solutions I could think of. Class Computed PropertyUsing Template HelperIdeally, I would like to use a hypothetical const sourceObject = {
foo: 'ember',
bar: 'light',
qux: {
quax: 'table'
}
};
const paths = ['bar', 'qux.quax']; {{get-multiple sourceObject paths}} {{! => ['light', 'table'] }} The helper is complex and reusable enough, that it's justified to be released as its own addon. The code should be based on |
hmm... so a helper that behaves like https://www.emberjs.com/api/ember/2.14/namespaces/Ember.computed/methods/collect?anchor=collect ? |
Exactly. And I think Unfortunately we won't be able to use the |
I created an I'm gonna submit a PR with a PoC soon. I'm interested in how much faster |
I've had a good night's sleep about it and got a viable idea for a third option. Create a new cell type
|
Turns out creating computed properties at run time isn't as easy as it seems. import Ember from 'ember';
import { defineProperty, get } from '@ember/object';
import { collect, reads } from '@ember/object/computed';
import { isArray } from '@ember/array';
import BaseCell from 'ember-light-table/components/cells/base';
const { propertyDidChange, propertyWillChange } = Ember;
function forceSet(obj, keyName, value) {
propertyWillChange(obj, keyName);
defineProperty(obj, keyName, value);
propertyDidChange(obj, keyName);
return value;
}
export default class extends BaseCell {
didReceiveAttrs() {
super.didReceiveAttrs(...arguments);
const valuePath = get(this, 'column.valuePath');
if (isArray(valuePath)) {
forceSet(this, 'rawValue', collect(...valuePath));
} else {
forceSet(this, 'rawValue', reads(valuePath));
}
}
} You can take a look at the twiddle demonstrating this. I am dead inside. 😂 But seriously, am I looking at this the wrong way? Why is such a basic thing so hard to do? |
Work has begun here: |
I often find myself needing to compute a cell's value dependent of more than one field of the row. But the current API allows only passing one key as the
valuePath
.I work around this by just accessing whatever properties I need from the
row
attribute that is passed to thecellComponent
. I think that's pretty ugly.If we would allow users to pass a string or an array of strings to
valuePath
, then (in the latter case) we could pass an array of values asvalue
to thecellComponent
.The text was updated successfully, but these errors were encountered: