Skip to content

Commit 6ed9a27

Browse files
committed
Remove EMBER_UNIQUE_ID_HELPER flag
1 parent 3607094 commit 6ed9a27

File tree

4 files changed

+129
-143
lines changed

4 files changed

+129
-143
lines changed

FEATURES.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,3 @@ for a detailed explanation.
99

1010
Provides a default manager for unrecognized helpers as specified in
1111
[RFC-756](https://github.com/emberjs/rfcs/blob/master/text/0756-helper-default-manager.md).
12-
13-
* `EMBER_UNIQUE_ID_HELPER`
14-
15-
Provides a `{{unique-id}} helper as specified in
16-
[RFC-659](https://github.com/emberjs/rfcs/blob/master/text/0659-unique-id-helper.md).

packages/@ember/-internals/glimmer/lib/resolver.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { privatize as P } from '@ember/-internals/container';
22
import { ENV } from '@ember/-internals/environment';
33
import type { InternalFactory, InternalOwner, RegisterOptions } from '@ember/-internals/owner';
44
import { isFactory } from '@ember/-internals/owner';
5-
import { EMBER_UNIQUE_ID_HELPER } from '@ember/canary-features';
65
import { assert } from '@ember/debug';
76
import { _instrumentStart } from '@ember/instrumentation';
87
import { DEBUG } from '@glimmer/env';
@@ -132,6 +131,7 @@ const BUILTIN_HELPERS: Record<string, object> = {
132131
fn,
133132
get,
134133
hash,
134+
'unique-id': uniqueId,
135135
};
136136

137137
if (DEBUG) {
@@ -148,10 +148,6 @@ if (DEBUG) {
148148
BUILTIN_HELPERS['-disallow-dynamic-resolution'] = disallowDynamicResolution;
149149
}
150150

151-
if (EMBER_UNIQUE_ID_HELPER) {
152-
BUILTIN_HELPERS['unique-id'] = uniqueId;
153-
}
154-
155151
const BUILTIN_KEYWORD_MODIFIERS: Record<string, ModifierDefinitionState> = {
156152
action: actionModifier,
157153
};
Lines changed: 128 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,165 +1,162 @@
11
import { RenderingTestCase, strip, moduleFor, runTask } from 'internal-test-helpers';
22
import { setProperties } from '@ember/object';
3-
import { EMBER_UNIQUE_ID_HELPER } from '@ember/canary-features';
4-
5-
if (EMBER_UNIQUE_ID_HELPER) {
6-
moduleFor(
7-
'Helpers test: {{unique-id}}',
8-
class extends RenderingTestCase {
9-
['@test it generates a unique id (string) each time']() {
10-
let { first, second } = this.render(`<p>{{unique-id}}</p><p>{{unique-id}}</p>`, () => {
3+
4+
moduleFor(
5+
'Helpers test: {{unique-id}}',
6+
class extends RenderingTestCase {
7+
['@test it generates a unique id (string) each time']() {
8+
let { first, second } = this.render(`<p>{{unique-id}}</p><p>{{unique-id}}</p>`, () => {
9+
let first = this.asElement(this.firstChild);
10+
let second = this.asElement(this.nthChild(1));
11+
12+
return {
13+
first: this.asTextContent(first.firstChild),
14+
second: this.asTextContent(second.firstChild),
15+
};
16+
});
17+
18+
this.assert.notStrictEqual(
19+
first,
20+
second,
21+
`different invocations of {{unique-id}} should produce different values`
22+
);
23+
}
24+
25+
[`@test when unique-id is used with #let, it remains stable when it's used`]() {
26+
let { first, second } = this.render(
27+
strip`
28+
{{#let (unique-id) as |id|}}
29+
<p>{{id}}</p><p>{{id}}</p>
30+
{{/let}}
31+
`,
32+
() => {
1133
let first = this.asElement(this.firstChild);
1234
let second = this.asElement(this.nthChild(1));
1335

1436
return {
1537
first: this.asTextContent(first.firstChild),
1638
second: this.asTextContent(second.firstChild),
1739
};
18-
});
19-
20-
this.assert.notStrictEqual(
21-
first,
22-
second,
23-
`different invocations of {{unique-id}} should produce different values`
24-
);
25-
}
26-
27-
[`@test when unique-id is used with #let, it remains stable when it's used`]() {
28-
let { first, second } = this.render(
29-
strip`
30-
{{#let (unique-id) as |id|}}
31-
<p>{{id}}</p><p>{{id}}</p>
32-
{{/let}}
33-
`,
34-
() => {
35-
let first = this.asElement(this.firstChild);
36-
let second = this.asElement(this.nthChild(1));
37-
38-
return {
39-
first: this.asTextContent(first.firstChild),
40-
second: this.asTextContent(second.firstChild),
41-
};
42-
}
43-
);
40+
}
41+
);
4442

45-
this.assert.strictEqual(
46-
first,
47-
second,
48-
`when unique-id is used as a variable, it remains the same`
49-
);
50-
}
43+
this.assert.strictEqual(
44+
first,
45+
second,
46+
`when unique-id is used as a variable, it remains the same`
47+
);
48+
}
5149

52-
[`@test unique-id doesn't change if it's concatenated with a value that does change`]() {
53-
class Elements {
54-
constructor(label, input, assert) {
55-
this.label = label;
56-
this.input = input;
57-
this.assert = assert;
58-
}
50+
[`@test unique-id doesn't change if it's concatenated with a value that does change`]() {
51+
class Elements {
52+
constructor(label, input, assert) {
53+
this.label = label;
54+
this.input = input;
55+
this.assert = assert;
56+
}
5957

60-
id(regex) {
61-
let forAttr = this.label.getAttribute('for');
58+
id(regex) {
59+
let forAttr = this.label.getAttribute('for');
6260

63-
this.assert.strictEqual(
64-
forAttr,
65-
this.input.getAttribute('id'),
66-
`the label's 'for' attribute should be the same as the input's 'id' attribute`
67-
);
61+
this.assert.strictEqual(
62+
forAttr,
63+
this.input.getAttribute('id'),
64+
`the label's 'for' attribute should be the same as the input's 'id' attribute`
65+
);
6866

69-
let match = forAttr.match(regex);
67+
let match = forAttr.match(regex);
7068

71-
this.assert.ok(match, 'the id starts with the prefix');
69+
this.assert.ok(match, 'the id starts with the prefix');
7270

73-
return match[1];
74-
}
71+
return match[1];
7572
}
73+
}
7674

77-
let { elements, id } = this.render(
78-
strip`
79-
{{#let (unique-id) as |id|}}
80-
<label for="{{this.prefix}}-{{id}}">Enable Feature</label>
81-
<input id="{{this.prefix}}-{{id}}" type="checkbox">
82-
{{/let}}`,
83-
{ prefix: 'app' },
84-
() => {
85-
let label = this.asElement(this.firstChild, 'label');
86-
let input = this.asElement(this.nthChild(1), 'input');
87-
88-
let elements = new Elements(label, input, this.assert);
89-
90-
return { elements, id: elements.id(/^app-(.*)$/) };
91-
}
92-
);
75+
let { elements, id } = this.render(
76+
strip`
77+
{{#let (unique-id) as |id|}}
78+
<label for="{{this.prefix}}-{{id}}">Enable Feature</label>
79+
<input id="{{this.prefix}}-{{id}}" type="checkbox">
80+
{{/let}}`,
81+
{ prefix: 'app' },
82+
() => {
83+
let label = this.asElement(this.firstChild, 'label');
84+
let input = this.asElement(this.nthChild(1), 'input');
9385

94-
this.update({ prefix: 'melanie' }, () => {
95-
let newId = elements.id(/^melanie-(.*)$/);
86+
let elements = new Elements(label, input, this.assert);
9687

97-
this.assert.strictEqual(
98-
id,
99-
newId,
100-
`the unique-id part of a concatenated attribute shouldn't change just because a dynamic part of it changed`
101-
);
102-
});
103-
}
88+
return { elements, id: elements.id(/^app-(.*)$/) };
89+
}
90+
);
10491

105-
['@test it only generates valid selectors']() {
106-
let iterations = 1000;
107-
let reNumericStart = /^\d/;
92+
this.update({ prefix: 'melanie' }, () => {
93+
let newId = elements.id(/^melanie-(.*)$/);
10894

109-
let template = '<p>{{unique-id}}</p>'.repeat(iterations);
110-
super.render(template);
95+
this.assert.strictEqual(
96+
id,
97+
newId,
98+
`the unique-id part of a concatenated attribute shouldn't change just because a dynamic part of it changed`
99+
);
100+
});
101+
}
111102

112-
for (let i = 0; i < iterations; i++) {
113-
let textNode = this.nthChild(i).firstChild;
114-
let text = textNode.data;
103+
['@test it only generates valid selectors']() {
104+
let iterations = 1000;
105+
let reNumericStart = /^\d/;
115106

116-
this.assert.false(
117-
reNumericStart.test(text),
118-
`{{unique-id}} should produce valid selectors` + text
119-
);
120-
}
121-
}
107+
let template = '<p>{{unique-id}}</p>'.repeat(iterations);
108+
super.render(template);
122109

123-
render(template, ...rest) {
124-
// If there are three parameters to `render`, the second parameter is the
125-
// template's arguments.
126-
let args = rest.length === 2 ? rest[0] : {};
127-
// If there are two parameters to `render`, the second parameter is the
128-
// postcondition. Otherwise, the third parameter is the postcondition.
129-
let postcondition = rest.length === 2 ? rest[1] : rest[0];
130-
131-
super.render(template, args);
132-
let result = postcondition();
133-
this.assertStableRerender();
134-
return result;
135-
}
110+
for (let i = 0; i < iterations; i++) {
111+
let textNode = this.nthChild(i).firstChild;
112+
let text = textNode.data;
136113

137-
update(args, postcondition) {
138-
runTask(() => setProperties(this.context, args));
139-
postcondition();
140-
this.assertStableRerender();
114+
this.assert.false(
115+
reNumericStart.test(text),
116+
`{{unique-id}} should produce valid selectors` + text
117+
);
141118
}
119+
}
142120

143-
asElement(node, tag) {
144-
this.assert.ok(node !== null && node.nodeType === 1);
121+
render(template, ...rest) {
122+
// If there are three parameters to `render`, the second parameter is the
123+
// template's arguments.
124+
let args = rest.length === 2 ? rest[0] : {};
125+
// If there are two parameters to `render`, the second parameter is the
126+
// postcondition. Otherwise, the third parameter is the postcondition.
127+
let postcondition = rest.length === 2 ? rest[1] : rest[0];
128+
129+
super.render(template, args);
130+
let result = postcondition();
131+
this.assertStableRerender();
132+
return result;
133+
}
145134

146-
if (tag) {
147-
this.assert.strictEqual(node.tagName.toLowerCase(), tag, `Element is <${tag}>`);
148-
}
135+
update(args, postcondition) {
136+
runTask(() => setProperties(this.context, args));
137+
postcondition();
138+
this.assertStableRerender();
139+
}
149140

150-
return node;
151-
}
141+
asElement(node, tag) {
142+
this.assert.ok(node !== null && node.nodeType === 1);
152143

153-
asTextNode(node) {
154-
this.assert.ok(node !== null && node.nodeType === 3);
155-
return node;
144+
if (tag) {
145+
this.assert.strictEqual(node.tagName.toLowerCase(), tag, `Element is <${tag}>`);
156146
}
157147

158-
asTextContent(node) {
159-
let data = this.asTextNode(node).data;
160-
this.assert.ok(data.trim().length > 0, `The text node has content`);
161-
return data;
162-
}
148+
return node;
149+
}
150+
151+
asTextNode(node) {
152+
this.assert.ok(node !== null && node.nodeType === 3);
153+
return node;
154+
}
155+
156+
asTextContent(node) {
157+
let data = this.asTextNode(node).data;
158+
this.assert.ok(data.trim().length > 0, `The text node has content`);
159+
return data;
163160
}
164-
);
165-
}
161+
}
162+
);

packages/@ember/canary-features/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { ENV } from '@ember/-internals/environment';
1212
*/
1313

1414
export const DEFAULT_FEATURES = {
15-
EMBER_UNIQUE_ID_HELPER: true,
1615
EMBER_DEFAULT_HELPER_MANAGER: true,
1716
};
1817

@@ -62,5 +61,4 @@ function featureValue(value: null | boolean) {
6261
return value;
6362
}
6463

65-
export const EMBER_UNIQUE_ID_HELPER = featureValue(FEATURES.EMBER_UNIQUE_ID_HELPER);
6664
export const EMBER_DEFAULT_HELPER_MANAGER = featureValue(FEATURES.EMBER_DEFAULT_HELPER_MANAGER);

0 commit comments

Comments
 (0)