Function

notEmpty (dependentKey) ComputedProperty public

Module: @ember/object
import { notEmpty } from '@ember/object/computed';
dependentKey
String
returns
ComputedProperty
computed property which returns true if original value for property is not empty.

A computed property that returns true if the value of the dependent property is NOT null, an empty string, empty array, or empty function.

Example:

import { set } from '@ember/object';
import { notEmpty } from '@ember/object/computed';

class Hamster {
  constructor(backpack) {
    set(this, 'backpack', backpack);
  }

  @notEmpty('backpack') hasStuff
}

let hamster = new Hamster(
  ['Food', 'Sleeping Bag', 'Tent']
);

hamster.hasStuff; // true
set(hamster, 'backpack', []);
hamster.hasStuff; // false

Classic Class Example:

import EmberObject, { set } from '@ember/object';
import { notEmpty } from '@ember/object/computed';

let Hamster = EmberObject.extend({
  hasStuff: notEmpty('backpack')
});

let hamster = Hamster.create({
  backpack: ['Food', 'Sleeping Bag', 'Tent']
});

hamster.hasStuff; // true
set(hamster, 'backpack', []);
hamster.hasStuff; // false

© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/3.25/functions/@ember%2Fobject%2Fcomputed/notEmpty