Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed the helpers by dropping the cq prefix #146

Merged
merged 7 commits into from
Jan 3, 2023
Merged

Conversation

ijlee2
Copy link
Owner

@ijlee2 ijlee2 commented Jan 3, 2023

Description

In light of strict mode template support (#130), I decided to rename the helpers by dropping the cq prefix. This lets us (1) minimize the syntax difference (e.g. in documentation) and (2) write templates that are easier to read and understand:

{{! Option 1: app/components/tracks.hbs }}

<ContainerQuery
  @features={{hash
    small=(width max=480)
    medium=(width min=480 max=640)
    large=(width min=640)
    tall=(height min=320)
  }}
  as |CQ|
>
  ...
</ContainerQuery>
/* Option 2: app/components/tracks.gts */

import { hash } from '@ember/helper';
import { ContainerQuery, height, width } from 'ember-container-query';

<template>
  <ContainerQuery
    @features={{hash
      small=(width max=480)
      medium=(width min=480 max=640)
      large=(width min=640)
      tall=(height min=320)
    }}
    as |CQ|
  >
    ...
  </ContainerQuery>
</template>

One downside is, the names height and width are less unique. More search results (e.g. from a whole string match) will be produced and it is up to the end-developer to sift the results.

To be clear, this pull request does not introduce a breaking change. The old helpers ({{cq-aspect-ratio}}, {{cq-height}} and {{cq-width}}) continue to be available, but now produce a deprecation message. They will be removed in the v4.0.0 release.

Migration strategy for end-developers

The helpers have been renamed by dropping the cq prefix. As a result, you can use your text editor's find-and-replace-all to update the helper names.

Step Find Replace with
1 cq-aspect-ratio aspect-ratio
2 cq-height height
3 cq-width width

The three steps are demonstrated in commits 3-5 of this pull request.

How to fix name collisions

Scenario 1

You may be using the names height and width for arguments or properties of a component. If so, follow the Octane syntax and clearly mark them as arguments (@) or properties (this.). Linters (e.g. ember-template-lint, eslint-plugin-ember, and glint) can help you fix these name collisions.

Here is an extreme example:

{{! app/components/edge-case.hbs }}

<div>
  Arguments:
  {{@aspectRatio}},
  {{@height}},
  {{@width}}
</div>

<div>
  {{#let
    (hash
      aspect-ratio=(aspect-ratio) height=(height) width=(width)
    )
    as |obj|
  }}
    {{! template-lint-disable no-log }}
    {{log obj.aspect-ratio obj.height obj.width}}
  {{/let}}
</div>

Scenario 2

When you have another addon that provides helpers named {{aspect-ratio}}, {{height}}, and {{width}}, you will need to decide which addon gets to keep the name.

This scenario is unlikely according to ember-observer:

@ijlee2 ijlee2 added the enhance: code Issue asks for new feature or refactor label Jan 3, 2023
Comment on lines +11 to +13
'cq-aspect-ratio': typeof AspectRatioHelper;
'cq-height': typeof HeightHelper;
'cq-width': typeof WidthHelper;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reminder

Remove these lines in the future pull request, which will remove {{cq-aspect-ratio}}, {{cq-height}}, and {{cq-width}} helpers.

Comment on lines +1 to +18
import { deprecate } from '@ember/debug';

deprecate(
'The {{cq-aspect-ratio}} helper has been renamed to {{aspect-ratio}}. Please update the helper name in your template.',
false,
{
for: 'ember-container-query',
id: 'ember-container-query.rename-cq-aspect-ratio-helper',
since: {
available: '3.2.0',
enabled: '3.2.0',
},
until: '4.0.0',
url: 'https://github.com/ijlee2/ember-container-query/tree/3.2.0#api',
}
);

export { default } from 'ember-container-query/helpers/aspect-ratio';
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reminder

Remove these lines in the future pull request, which will remove {{cq-aspect-ratio}}, {{cq-height}}, and {{cq-width}} helpers.

Comment on lines +1 to +18
import { deprecate } from '@ember/debug';

deprecate(
'The {{cq-height}} helper has been renamed to {{height}}. Please update the helper name in your template.',
false,
{
for: 'ember-container-query',
id: 'ember-container-query.rename-cq-height-helper',
since: {
available: '3.2.0',
enabled: '3.2.0',
},
until: '4.0.0',
url: 'https://github.com/ijlee2/ember-container-query/tree/3.2.0#api',
}
);

export { default } from 'ember-container-query/helpers/height';
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reminder

Remove these lines in the future pull request, which will remove {{cq-aspect-ratio}}, {{cq-height}}, and {{cq-width}} helpers.

Comment on lines +1 to +18
import { deprecate } from '@ember/debug';

deprecate(
'The {{cq-width}} helper has been renamed to {{width}}. Please update the helper name in your template.',
false,
{
for: 'ember-container-query',
id: 'ember-container-query.rename-cq-width-helper',
since: {
available: '3.2.0',
enabled: '3.2.0',
},
until: '4.0.0',
url: 'https://github.com/ijlee2/ember-container-query/tree/3.2.0#api',
}
);

export { default } from 'ember-container-query/helpers/width';
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reminder

Remove these lines in the future pull request, which will remove {{cq-aspect-ratio}}, {{cq-height}}, and {{cq-width}} helpers.

import { setupRenderingTest } from 'dummy/tests/helpers';
import { hbs } from 'ember-cli-htmlbars';
import { module, test } from 'qunit';

module('Integration | Helper | cq-aspect-ratio', function (hooks) {
setupRenderingTest(hooks);

test('can return a hash with default values', async function (this: TestContext, assert) {
test('provides a deprecation message', async function (this: TestContext, assert) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reminder

Delete this file in the future pull request, which will remove {{cq-aspect-ratio}}, {{cq-height}}, and {{cq-width}} helpers.

import { setupRenderingTest } from 'dummy/tests/helpers';
import { hbs } from 'ember-cli-htmlbars';
import { module, test } from 'qunit';

module('Integration | Helper | cq-height', function (hooks) {
setupRenderingTest(hooks);

test('can return a hash with default values', async function (this: TestContext, assert) {
test('provides a deprecation message', async function (this: TestContext, assert) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reminder

Delete this file in the future pull request, which will remove {{cq-aspect-ratio}}, {{cq-height}}, and {{cq-width}} helpers.

import { setupRenderingTest } from 'dummy/tests/helpers';
import { hbs } from 'ember-cli-htmlbars';
import { module, test } from 'qunit';

module('Integration | Helper | cq-width', function (hooks) {
setupRenderingTest(hooks);

test('can return a hash with default values', async function (this: TestContext, assert) {
test('provides a deprecation message', async function (this: TestContext, assert) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reminder

Delete this file in the future pull request, which will remove {{cq-aspect-ratio}}, {{cq-height}}, and {{cq-width}} helpers.

@ijlee2 ijlee2 marked this pull request as ready for review January 3, 2023 15:32
@ijlee2 ijlee2 merged commit b9d3dc8 into main Jan 3, 2023
@ijlee2 ijlee2 deleted the rename-helpers branch January 3, 2023 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhance: code Issue asks for new feature or refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant