New computed property: uniquely

Wraps up a common pattern used in charts for building a a string that
incorporates the ember guid
This commit is contained in:
Michael Lange 2021-02-12 15:21:01 -08:00
parent 12069efc3e
commit ce8b9c42f2
1 changed files with 12 additions and 0 deletions

View File

@ -0,0 +1,12 @@
import { computed } from '@ember/object';
import { guidFor } from '@ember/object/internals';
// An Ember.Computed property for creating a unique string with a
// common prefix (based on the guid of the object with the property)
//
// ex. @uniquely('name') // 'name-ember129383'
export default function uniquely(prefix) {
return computed(function() {
return `${prefix}-${guidFor(this)}`;
});
}