« All deprecation guides

Deprecation Guide for Use Ember.String.htmlSafe over Ember.Handlebars.SafeString

until: 3.0.0
id: use-ember-string-htmlsafe-over-ember-handlebars-safestring

Creating safe strings. Before:

import Ember from 'ember';
const { computed } = Ember;

export default Ember.Component.extend({
  myString: computed(function(){
    return new Ember.Handlebars.SafeString(someString);
  });
})

After:

import Ember from 'ember';
const { computed } = Ember;

export default Ember.Component.extend({
  myString: computed(function(){
    return Ember.String.htmlSafe(someString);
  });
)};

Detecting safe strings. Before:

import Ember from 'ember';

export default Ember.Component.extend({
  actions: {
    save() {
      let myString = this.get('myString');
      if (myString instanceof Ember.Handlebars.SafeString) {
        // ...
      }
    }
  }
});

After:

import Ember from 'ember';

export default Ember.Component.extend({
  actions: {
    save() {
      let myString = this.get('myString');
      if (Ember.String.isHTMLSafe(myString)) {
        // ...
      }
    }
  }
});

If you're an addon maintainer, there is a polyfill for safe string detection (ember-string-ishtmlsafe-polyfill) that will help maintain backwards compatibility. Additionally, it's worth noting that Ember.String.htmlSafe is supported back to pre-1.0, so there should be no concerns of backwards compatibility there.