Quantcast
Viewing all articles
Browse latest Browse all 4827

Best way to get attrs only

@xiwcx wrote:

Hi! I’m working on my first Ember addon and I needed a way to separate the attrs from the rest of the component object. I came across warnings against using this.attrs directly. What I came up with is:

const getComponentAttrs = that => Object.keys(that.attrs)
    .reduce((attrs, attrName) => {
        attrs[attrName] = that[attrName];

        return attrs;
    }, {});

invoked like so:

didUpdateAttrs() {
    this._super(...arguments);

    const attrs = getComponentAttrs(this);

    // and so on...
},

Any thoughts on this approach? Is there a better or common method?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4827

Trending Articles