Skip to content

Commit

Permalink
Merge pull request #11900 from rwjblue/deprecate-various-helpery-things
Browse files Browse the repository at this point in the history
Deprecate legacy helper versions.
  • Loading branch information
rwjblue committed Jul 26, 2015
2 parents 2c137a1 + a3d268d commit 68719dd
Show file tree
Hide file tree
Showing 17 changed files with 175 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,19 @@ QUnit.test('the default resolver resolves helpers on the namespace', function()
let ShorthandHelper = makeHelper(function() {});
let CompleteHelper = Helper.extend();
let LegacyBareFunctionHelper = function() {};
let LegacyHandlebarsBoundHelper = makeHandlebarsBoundHelper(function() {});
let LegacyHTMLBarsBoundHelper = makeHTMLBarsBoundHelper(function() {});
let ViewHelper = makeViewHelper(function() {});
let ViewHelper, LegacyHandlebarsBoundHelper, LegacyHTMLBarsBoundHelper;

expectDeprecation(function() {
LegacyHandlebarsBoundHelper = makeHandlebarsBoundHelper(function() {});
}, 'Using Ember.Handlebars.makeBoundHelper is deprecated. Please refactor to using `Ember.Helper.helper`.');

expectDeprecation(function() {
LegacyHTMLBarsBoundHelper = makeHTMLBarsBoundHelper(function() {});
}, 'Using `Ember.HTMLBars.makeBoundHelper` is deprecated. Please refactor to using `Ember.Helper` or `Ember.Helper.helper`.');

expectDeprecation(function() {
ViewHelper = makeViewHelper(function() {});
}, '`Ember.Handlebars.makeViewHelper` and `Ember.HTMLBars.makeViewHelper` are deprecated. Please refactor to normal component usage.');

application.ShorthandHelper = ShorthandHelper;
application.CompleteHelper = CompleteHelper;
Expand Down
12 changes: 12 additions & 0 deletions packages/ember-htmlbars/lib/compat/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ HandlebarsCompatibleHelper.prototype = {
};

export function registerHandlebarsCompatibleHelper(name, value) {
Ember.deprecate(
'Ember.Handlebars.registerHelper is deprecated, please refactor to Ember.Helper.helper.',
false,
{ id: 'ember-htmlbars.handlebars-register-helper', until: '2.0.0' }
);

if (value && value.isLegacyViewHelper) {
registerKeyword(name, function(morph, env, scope, params, hash, template, inverse, visitor) {
Ember.assert('You can only pass attributes (such as name=value) not bare ' +
Expand All @@ -132,6 +138,12 @@ export function registerHandlebarsCompatibleHelper(name, value) {
}

export function handlebarsHelper(name, value) {
Ember.deprecate(
'Ember.Handlebars.helper is deprecated, please refactor to Ember.Helper.helper',
false,
{ id: 'ember-htmlbars.handlebars-helper', until: '2.0.0' }
);

Ember.assert(`You tried to register a component named '${name}', but component names must include a '-'`,
!Component.detect(value) || name.match(/-/));

Expand Down
13 changes: 12 additions & 1 deletion packages/ember-htmlbars/lib/compat/make-bound-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ import {
@deprecated
@private
*/
export default function makeBoundHelper(fn, ...dependentKeys) {

export function makeBoundHelper(fn, ...dependentKeys) {
return {
_dependentKeys: dependentKeys,

Expand Down Expand Up @@ -65,3 +66,13 @@ export default function makeBoundHelper(fn, ...dependentKeys) {
}
};
}

export default function deprecatedMakeBoundHelper(fn, ...dependentKeys) {
Ember.deprecate(
'Using Ember.Handlebars.makeBoundHelper is deprecated. Please refactor to using `Ember.Helper.helper`.',
false,
{ id: 'ember-htmlbars.handlebars-make-bound-helper', until: '2.0.0' }
);

return makeBoundHelper(...arguments);
}
16 changes: 14 additions & 2 deletions packages/ember-htmlbars/lib/compat/register-bound-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
@submodule ember-htmlbars
*/

import Ember from 'ember-metal/core';
import helpers from 'ember-htmlbars/helpers';
import makeBoundHelper from 'ember-htmlbars/compat/make-bound-helper';
import { makeBoundHelper } from 'ember-htmlbars/compat/make-bound-helper';

var slice = [].slice;

Expand Down Expand Up @@ -118,9 +119,20 @@ var slice = [].slice;
@param {String} dependentKeys*
@private
*/
export default function registerBoundHelper(name, fn) {

export function registerBoundHelper(name, fn) {
var boundHelperArgs = slice.call(arguments, 1);
var boundFn = makeBoundHelper.apply(this, boundHelperArgs);

helpers[name] = boundFn;
}

export default function deprecatedRegisterBoundHelper() {
Ember.deprecate(
'`Ember.Handlebars.registerBoundHelper` is deprecated. Please refactor to use `Ember.Helpers.helper`.',
false,
{ id: 'ember-htmlbars.register-bound-helper', until: '2.0.0' }
);

return registerBoundHelper(...arguments);
}
7 changes: 7 additions & 0 deletions packages/ember-htmlbars/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
@private
@property helpers
*/
import Ember from 'ember-metal/core';

var helpers = Object.create(null);

/**
Expand All @@ -25,4 +27,9 @@ export function registerHelper(name, helperFunc) {
helpers[name] = helperFunc;
}

export let deprecatedRegisterHelper = Ember.deprecateFunc(
'Using Ember.HTMLBars._registerHelper is deprecated. Helpers (even dashless ones) are automatically resolved.',
{ id: 'ember-htmlbars.register-helper', until: '2.0.0' },
registerHelper);

export default helpers;
5 changes: 3 additions & 2 deletions packages/ember-htmlbars/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import makeViewHelper from 'ember-htmlbars/system/make-view-helper';
import makeBoundHelper from 'ember-htmlbars/system/make_bound_helper';

import {
registerHelper
registerHelper,
deprecatedRegisterHelper
} from 'ember-htmlbars/helpers';
import {
ifHelper,
Expand Down Expand Up @@ -84,7 +85,7 @@ if (Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT) {
}

Ember.HTMLBars = {
_registerHelper: registerHelper,
_registerHelper: deprecatedRegisterHelper,
template: template,
compile: compile,
precompile: precompile,
Expand Down
8 changes: 8 additions & 0 deletions packages/ember-htmlbars/lib/system/make-view-helper.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Ember from 'ember-metal/core';

/**
@module ember
@submodule ember-htmlbars
Expand All @@ -15,6 +17,12 @@
@since 1.2.0
*/
export default function makeViewHelper(ViewClass) {
Ember.deprecate(
'`Ember.Handlebars.makeViewHelper` and `Ember.HTMLBars.makeViewHelper` are deprecated. Please refactor to normal component usage.',
false,
{ id: 'ember-htmlbars.make-view-helper', until: '2.0.0' }
);

return {
isLegacyViewHelper: true,
isHTMLBars: true,
Expand Down
7 changes: 6 additions & 1 deletion packages/ember-htmlbars/lib/system/make_bound_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@module ember
@submodule ember-htmlbars
*/

import Ember from 'ember-metal/core';
import { helper } from 'ember-htmlbars/helper';

/**
Expand Down Expand Up @@ -49,5 +49,10 @@ import { helper } from 'ember-htmlbars/helper';
@since 1.10.0
*/
export default function makeBoundHelper(fn) {
Ember.deprecate(
'Using `Ember.HTMLBars.makeBoundHelper` is deprecated. Please refactor to using `Ember.Helper` or `Ember.Helper.helper`.',
false,
{ id: 'ember-htmlbars.make-bound-helper', until: '3.0.0' }
);
return helper(fn);
}
47 changes: 30 additions & 17 deletions packages/ember-htmlbars/tests/compat/helper_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
registerHandlebarsCompatibleHelper
registerHandlebarsCompatibleHelper as registerHelper
} from 'ember-htmlbars/compat/helper';

import EmberView from 'ember-views/views/view';
Expand All @@ -18,6 +18,12 @@ import viewKeyword from 'ember-htmlbars/keywords/view';

var view, registry, container, originalViewKeyword;

function registerHandlebarsCompatibleHelper() {
expectDeprecation('Ember.Handlebars.registerHelper is deprecated, please refactor to Ember.Helper.helper.');

return registerHelper(...arguments);
}

QUnit.module('ember-htmlbars: compat - Handlebars compatible helpers', {
setup() {
originalViewKeyword = registerKeyword('view', viewKeyword);
Expand All @@ -40,7 +46,7 @@ QUnit.module('ember-htmlbars: compat - Handlebars compatible helpers', {
});

QUnit.test('wraps provided function so that original path params are provided to the helper', function() {
expect(2);
expect(3);

function someHelper(param1, param2, options) {
equal(param1, 'blammo');
Expand All @@ -60,7 +66,7 @@ QUnit.test('wraps provided function so that original path params are provided to
});

QUnit.test('combines `env` and `options` for the wrapped helper', function() {
expect(1);
expect(2);

function someHelper(options) {
equal(options.data.view, view);
Expand All @@ -79,7 +85,7 @@ QUnit.test('combines `env` and `options` for the wrapped helper', function() {
});

QUnit.test('combines `env` and `options` for the wrapped helper', function() {
expect(1);
expect(2);

function someHelper(options) {
equal(options.data.view, view);
Expand Down Expand Up @@ -122,7 +128,7 @@ QUnit.test('has the correct options.data.view within a components layout', funct
});

QUnit.test('adds `hash` into options `options` for the wrapped helper', function() {
expect(1);
expect(2);

function someHelper(options) {
equal(options.hash.bestFriend, 'Jacquie');
Expand All @@ -141,7 +147,7 @@ QUnit.test('adds `hash` into options `options` for the wrapped helper', function
});

QUnit.test('bound `hash` params are provided with their original paths', function() {
expect(1);
expect(2);

function someHelper(options) {
equal(options.hash.bestFriend, 'value');
Expand All @@ -160,7 +166,7 @@ QUnit.test('bound `hash` params are provided with their original paths', functio
});

QUnit.test('bound ordered params are provided with their original paths', function() {
expect(2);
expect(3);

function someHelper(param1, param2, options) {
equal(param1, 'first');
Expand All @@ -181,13 +187,17 @@ QUnit.test('bound ordered params are provided with their original paths', functi
});

QUnit.test('registering a helper created from `Ember.Handlebars.makeViewHelper` does not double wrap the helper', function() {
expect(1);
expect(3);

var ViewHelperComponent = Component.extend({
layout: compile('woot!')
});

var helper = makeViewHelper(ViewHelperComponent);
var helper;
expectDeprecation(function() {
helper = makeViewHelper(ViewHelperComponent);
}, '`Ember.Handlebars.makeViewHelper` and `Ember.HTMLBars.makeViewHelper` are deprecated. Please refactor to normal component usage.');

registerHandlebarsCompatibleHelper('view-helper', helper);

view = EmberView.extend({
Expand All @@ -200,15 +210,18 @@ QUnit.test('registering a helper created from `Ember.Handlebars.makeViewHelper`
});

QUnit.test('makes helpful assertion when called with invalid arguments', function() {
expect(1);
expect(3);

var ViewHelperComponent = Component.extend({
layout: compile('woot!')
});

ViewHelperComponent.toString = function() { return 'Some Random Class'; };

var helper = makeViewHelper(ViewHelperComponent);
var helper;
expectDeprecation(function() {
helper = makeViewHelper(ViewHelperComponent);
}, '`Ember.Handlebars.makeViewHelper` and `Ember.HTMLBars.makeViewHelper` are deprecated. Please refactor to normal component usage.');
registerHandlebarsCompatibleHelper('view-helper', helper);

view = EmberView.extend({
Expand All @@ -221,7 +234,7 @@ QUnit.test('makes helpful assertion when called with invalid arguments', functio
});

QUnit.test('does not add `options.fn` if no block was specified', function() {
expect(1);
expect(2);

function someHelper(options) {
ok(!options.fn, '`options.fn` is not present when block is not specified');
Expand All @@ -240,7 +253,7 @@ QUnit.test('does not add `options.fn` if no block was specified', function() {
});

QUnit.test('does not return helper result if block was specified', function() {
expect(1);
expect(2);

function someHelper(options) {
return 'asdf';
Expand All @@ -261,7 +274,7 @@ QUnit.test('does not return helper result if block was specified', function() {
});

QUnit.test('allows usage of the template fn', function() {
expect(1);
expect(2);

function someHelper(options) {
options.fn();
Expand All @@ -282,7 +295,7 @@ QUnit.test('allows usage of the template fn', function() {
});

QUnit.test('allows usage of the template inverse', function() {
expect(1);
expect(2);

function someHelper(options) {
options.inverse();
Expand All @@ -303,7 +316,7 @@ QUnit.test('allows usage of the template inverse', function() {
});

QUnit.test('ordered param types are added to options.types', function() {
expect(3);
expect(4);

function someHelper(param1, param2, param3, options) {
equal(options.types[0], 'NUMBER');
Expand All @@ -325,7 +338,7 @@ QUnit.test('ordered param types are added to options.types', function() {
});

QUnit.test('`hash` params are to options.hashTypes', function() {
expect(3);
expect(4);

function someHelper(options) {
equal(options.hashTypes.string, 'STRING');
Expand Down
9 changes: 7 additions & 2 deletions packages/ember-htmlbars/tests/compat/make-view-helper_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@ QUnit.module('ember-htmlbars: compat - makeViewHelper compat', {
});

QUnit.test('makeViewHelper', function() {
expect(1);
expect(2);

var ViewHelperComponent = Component.extend({
layout: compile('woot!')
});
var helper = makeViewHelper(ViewHelperComponent);

var helper;
expectDeprecation(function() {
helper = makeViewHelper(ViewHelperComponent);
}, '`Ember.Handlebars.makeViewHelper` and `Ember.HTMLBars.makeViewHelper` are deprecated. Please refactor to normal component usage.');

registry.register('helper:view-helper', helper);

view = EmberView.extend({
Expand Down
13 changes: 1 addition & 12 deletions packages/ember-htmlbars/tests/compat/make_bound_helper_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,14 @@ function expectDeprecationInHTMLBars() {

QUnit.module('ember-htmlbars: compat - makeBoundHelper', {
setup() {
expectDeprecation('Using Ember.Handlebars.makeBoundHelper is deprecated. Please refactor to using `Ember.Helper.helper`.');
},
teardown() {
runDestroy(view);
Ember.lookup = originalLookup;
}
});

QUnit.test('primitives should work correctly [DEPRECATED]', function() {
view = EmberView.create({
prims: Ember.A(['string', 12]),

template: compile('{{#each view.prims as |prim|}}{{#if prim}}inside-if{{/if}}{{/each}}')
});

runAppend(view);

equal(view.$().text(), 'inside-ifinside-if');
});

QUnit.test('should update bound helpers when properties change', function() {
expectDeprecationInHTMLBars();

Expand Down
Loading

0 comments on commit 68719dd

Please sign in to comment.