Skip to content

Commit

Permalink
feat: deprecate custom decorators
Browse files Browse the repository at this point in the history
the function "registerDecorator" is now deprecated. The
decorator API exposes a lot of internal structures that
should not be part of the official API. An alternative
API can be discussed at #1574
- "Handlebars.registerDecorator" now logs a warning
- "Handlebars.registerDecoratorWithoutDeprecationWarning"
  can be used in order to omit the warning, when
  developers have read the notice.
  (The inline-decorator is using this function now)
  • Loading branch information
nknapp committed Oct 28, 2019
1 parent b24797d commit 7d9995d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/handlebars/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,19 @@ HandlebarsEnvironment.prototype = {
},

registerDecorator: function(name, fn) {
this.log('warn', 'Custom decorators are deprecated and will be removed in the future. Join the discussion at https://github.com/wycats/handlebars.js/issues/1574');
this.registerDecoratorWithoutDeprecationWarning(name, fn);
},

registerDecoratorWithoutDeprecationWarning: function(name, fn) {
if (toString.call(name) === objectType) {
if (fn) { throw new Exception('Arg not supported with multiple decorators'); }
extend(this.decorators, name);
} else {
this.decorators[name] = fn;
}
},

unregisterDecorator: function(name) {
delete this.decorators[name];
}
Expand Down
2 changes: 1 addition & 1 deletion lib/handlebars/decorators/inline.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {extend} from '../utils';

export default function(instance) {
instance.registerDecorator('inline', function(fn, props, container, options) {
instance.registerDecoratorWithoutDeprecationWarning('inline', function(fn, props, container, options) {
let ret = fn;
if (!props.partials) {
props.partials = {};
Expand Down
2 changes: 1 addition & 1 deletion spec/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ describe('blocks', function() {
equals(run, true);
});

describe('registration', function() {
describe.only('registration', function() {
it('unregisters', function() {
handlebarsEnv.decorators = {};

Expand Down

0 comments on commit 7d9995d

Please sign in to comment.