Git Product home page Git Product logo

Comments (1)

ijlee2 avatar ijlee2 commented on May 24, 2024

@IgnaceMaes Thanks for reporting a case that I didn't account for in 6.3.0. Namely, an end-developer may override one of the helpers and invert the default value of this.allowEmpty.

In 6.3.0, I removed allowEmpty as a class property, because I found the line options.allowEmpty ?? this.allowEmpty to be confusing (back when ember-intl's helpers inherited a base class). Strangely, {{format-date}} had been the only helper that had set this.allowEmpty to true, so I figured it's unnecessary to have a class property.


I think how you overrode the {{t}} helper and passed allowEmpty: true is okay. It may be a brittle solution, since your helper and how you provide types depend on ember-intl's current implementation.

Because there's another regression from 6.3.0 that I want to fix, I can temporarily revert removing the class property this.allowEmpty so that you can still use the syntax,

import THelper from 'ember-intl/helpers/t';

export default class extends THelper {
  allowEmpty = true;
}

Going forward, what we could try is to make all helpers not throw an error when the value provided is either undefined or null, i.e. we replace the lines,

/* In v6.3.1 */
compute([value]) {
  if (isEmpty(value)) {
    if (options?.allowEmpty ?? this.allowEmpty) {
      return '';
    }

    throw new Error('...');
  }

  // ...
}

with,

/* At a later point */
compute([value]) {
  if (value === undefined || value === null) {
    return '';
  }

  // ...
}

Removing isEmpty() would allow me to do type check more easily, and allow end-developers to skip the step of defining options.allowEmpty. I currently don't see a reason for helpers to throw an error (the intl service could still throw an error, e.g. for missing translations).

from ember-intl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.