Skip to content

Commit

Permalink
[FEATURE default helper manager] Add the default helper manager
Browse files Browse the repository at this point in the history
This updates the Glimmer VM to version 0.84.1 which includes the default helper manager and a feature flag to conditionally enable that feature in Ember.
  • Loading branch information
Windvis committed Apr 9, 2022
1 parent 32dc083 commit aa53c47
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 171 deletions.
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@babel/helper-module-imports": "^7.16.7",
"@babel/plugin-transform-block-scoping": "^7.16.0",
"@ember/edition-utils": "^1.2.0",
"@glimmer/vm-babel-plugins": "0.83.1",
"@glimmer/vm-babel-plugins": "0.84.1",
"babel-plugin-debug-macros": "^0.3.4",
"babel-plugin-filter-imports": "^4.0.0",
"broccoli-concat": "^4.2.5",
Expand All @@ -78,19 +78,19 @@
},
"devDependencies": {
"@babel/preset-env": "^7.16.11",
"@glimmer/compiler": "0.84.0",
"@glimmer/destroyable": "0.83.1",
"@glimmer/compiler": "0.84.1",
"@glimmer/destroyable": "0.84.1",
"@glimmer/env": "^0.1.7",
"@glimmer/global-context": "0.83.1",
"@glimmer/interfaces": "0.83.1",
"@glimmer/manager": "0.83.1",
"@glimmer/node": "0.83.1",
"@glimmer/opcode-compiler": "0.83.1",
"@glimmer/owner": "0.84.0",
"@glimmer/program": "0.83.1",
"@glimmer/reference": "0.83.1",
"@glimmer/runtime": "0.83.1",
"@glimmer/validator": "0.83.1",
"@glimmer/global-context": "0.84.1",
"@glimmer/interfaces": "0.84.1",
"@glimmer/manager": "0.84.1",
"@glimmer/node": "0.84.1",
"@glimmer/opcode-compiler": "0.84.1",
"@glimmer/owner": "0.84.1",
"@glimmer/program": "0.84.1",
"@glimmer/reference": "0.84.1",
"@glimmer/runtime": "0.84.1",
"@glimmer/validator": "0.84.1",
"@simple-dom/document": "^1.4.0",
"@types/qunit": "^2.11.3",
"@types/rsvp": "^4.0.4",
Expand Down
5 changes: 5 additions & 0 deletions packages/@ember/-internals/glimmer/lib/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { get, set, _getProp, _setProp } from '@ember/-internals/metal';
import { Owner } from '@ember/-internals/owner';
import { getDebugName } from '@ember/-internals/utils';
import { constructStyleDeprecationMessage } from '@ember/-internals/views';
import { EMBER_DEFAULT_HELPER_MANAGER } from '@ember/canary-features';
import { assert, deprecate, warn } from '@ember/debug';
import { DeprecationOptions } from '@ember/debug/lib/deprecate';
import { schedule, _backburner } from '@ember/runloop';
Expand All @@ -19,6 +20,10 @@ import toBool from './utils/to-bool';
// Setup global context

setGlobalContext({
FEATURES: {
DEFAULT_HELPER_MANAGER: Boolean(EMBER_DEFAULT_HELPER_MANAGER),
},

scheduleRevalidate() {
_backburner.ensureInstance();
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { RenderingTestCase, moduleFor, runTask } from 'internal-test-helpers';
import { Component } from '@ember/-internals/glimmer';

moduleFor(
'Helpers test: default helper manager',
class extends RenderingTestCase {
'@feature(EMBER_DEFAULT_HELPER_MANAGER) plain functions can be used as a helper'() {
function hello() {
return 'hello';
}

this.render('{{(this.hello)}}', {
hello,
});

this.assertText('hello');

runTask(() => this.rerender());

this.assertText('hello');
}

'@feature(EMBER_DEFAULT_HELPER_MANAGER) plain functions passed as component arguments can be used as helpers'() {
function hello() {
return 'hello';
}

this.registerComponent('foo-bar', { template: '{{(@hello)}}' });

this.render(`<FooBar @hello={{this.hello}} />`, {
hello,
});

this.assertText('hello');

runTask(() => this.rerender());

this.assertText('hello');
}

'@feature(EMBER_DEFAULT_HELPER_MANAGER) plain functions stored on component properties can be used as helpers'() {
this.registerComponent('foo-bar', {
template: '{{(this.hello)}}',
ComponentClass: class extends Component {
hello = () => {
return 'hello';
};
},
});

this.render(`<FooBar />`);

this.assertText('hello');

runTask(() => this.rerender());

this.assertText('hello');
}

'@feature(EMBER_DEFAULT_HELPER_MANAGER) Class methods can be used as helpers'() {
this.registerComponent('foo-bar', {
template: '{{(this.hello)}}',
ComponentClass: class extends Component {
hello() {
return 'hello';
}
},
});

this.render(`<FooBar />`);

this.assertText('hello');

runTask(() => this.rerender());

this.assertText('hello');
}
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { helperCapabilities, setHelperManager } from '@glimmer/manager';
import { Helper, helper, Component as EmberComponent } from '@ember/-internals/glimmer';
import { tracked, set } from '@ember/-internals/metal';
import { getOwner } from '@ember/-internals/owner';
import { EMBER_DEFAULT_HELPER_MANAGER } from '@ember/canary-features';
import Service, { service } from '@ember/service';
import { DEBUG } from '@glimmer/env';
import { getValue } from '@glimmer/validator';
Expand Down Expand Up @@ -444,7 +445,7 @@ moduleFor(
}

'@test asserts if no manager exists for the helper definition'(assert) {
if (!DEBUG) {
if (!DEBUG || EMBER_DEFAULT_HELPER_MANAGER) {
assert.expect(0);
return;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/@ember/canary-features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const DEFAULT_FEATURES = {
EMBER_LIBRARIES_ISREGISTERED: null,
EMBER_IMPROVED_INSTRUMENTATION: null,
EMBER_UNIQUE_ID_HELPER: true,
EMBER_DEFAULT_HELPER_MANAGER: null,
};

/**
Expand Down Expand Up @@ -66,3 +67,4 @@ function featureValue(value: null | boolean) {
export const EMBER_LIBRARIES_ISREGISTERED = featureValue(FEATURES.EMBER_LIBRARIES_ISREGISTERED);
export const EMBER_IMPROVED_INSTRUMENTATION = featureValue(FEATURES.EMBER_IMPROVED_INSTRUMENTATION);
export const EMBER_UNIQUE_ID_HELPER = featureValue(FEATURES.EMBER_UNIQUE_ID_HELPER);
export const EMBER_DEFAULT_HELPER_MANAGER = featureValue(FEATURES.EMBER_DEFAULT_HELPER_MANAGER);
Loading

0 comments on commit aa53c47

Please sign in to comment.