Skip to content

Commit

Permalink
Add amp-bind experiment (ampproject#7157)
Browse files Browse the repository at this point in the history
* add amp-bind experiment

* add experiment check to amp-state

* fix unit test
  • Loading branch information
William Chou authored and jridgewell committed Jan 31, 2017
1 parent 9d6512a commit 4b3dd8b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
4 changes: 4 additions & 0 deletions extensions/amp-bind/0.1/amp-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import {bindForDoc} from '../../../src/bind';
import {isExperimentOn} from '../../../src/experiments';
import {isJsonScriptTag} from '../../../src/dom';
import {toggle} from '../../../src/style';
import {tryParseJson} from '../../../src/json';
Expand Down Expand Up @@ -47,6 +48,9 @@ export class AmpState extends AMP.BaseElement {

/** @override */
buildCallback() {
user().assert(isExperimentOn(this.win, 'amp-bind'),
`Experiment "amp-bind" is disabled.`);

const TAG = this.getName_();

toggle(this.element, false);
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-bind/0.1/bind-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {isExperimentOn} from '../../../src/experiments';
import {isFiniteNumber} from '../../../src/types';
import {resourcesForDoc} from '../../../src/resources';

const TAG = 'AMP-BIND';
const TAG = 'amp-bind';

/**
* Regular expression that identifies AMP CSS classes.
Expand Down
12 changes: 6 additions & 6 deletions extensions/amp-bind/0.1/test/test-bind-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describes.realWin('amp-bind', {
let canBindStub;

beforeEach(() => {
toggleExperiment(env.win, 'AMP-BIND', true);
toggleExperiment(env.win, 'amp-bind', true);

// Stub validator methods to return true for ease of testing.
canBindStub = env.sandbox.stub(
Expand All @@ -44,7 +44,7 @@ describes.realWin('amp-bind', {
});

afterEach(() => {
toggleExperiment(env.win, 'AMP-BIND', false);
toggleExperiment(env.win, 'amp-bind', false);
});

/**
Expand Down Expand Up @@ -105,10 +105,10 @@ describes.realWin('amp-bind', {
}

it('should throw error if experiment is not enabled', () => {
toggleExperiment(env.win, 'AMP-BIND', false);
toggleExperiment(env.win, 'amp-bind', false);
expect(() => {
new Bind(env.ampdoc);
}).to.throw('Experiment "AMP-BIND" is disabled.');
}).to.throw('Experiment "amp-bind" is disabled.');
});

it('should scan for bindings when ampdoc is ready', () => {
Expand All @@ -131,7 +131,7 @@ describes.realWin('amp-bind', {
env.sandbox.stub(window, 'AMP_MODE', {development: true});
// Only the initial value for [a] binding does not match.
createElementWithBinding('[a]="a" [b]="b" b="b"');
const errorStub = env.sandbox.stub(user(), 'error').withArgs('AMP-BIND');
const errorStub = env.sandbox.stub(user(), 'error').withArgs('amp-bind');
return onBindReady(() => {
expect(errorStub.callCount).to.equal(1);
});
Expand All @@ -141,7 +141,7 @@ describes.realWin('amp-bind', {
env.sandbox.stub(window, 'AMP_MODE', {development: true});
// Only the initial value for [c] binding does not match.
createElementWithBinding(`a [a]="true" [b]="false" c="false" [c]="false"`);
const errorStub = env.sandbox.stub(user(), 'error').withArgs('AMP-BIND');
const errorStub = env.sandbox.stub(user(), 'error').withArgs('amp-bind');
return onBindReady(() => {
expect(errorStub.callCount).to.equal(1);
});
Expand Down
7 changes: 7 additions & 0 deletions tools/experiments/experiments.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ const EXPERIMENTS = [
name: 'Format to apply filters to analytics variables',
cleanupIssue: 'https://github.com/ampproject/amphtml/issues/2198',
},
{
id: 'amp-bind',
name: 'AMP extension for dynamic content',
cleanupIssue: 'https://github.com/ampproject/amphtml/issues/7156',
spec: 'https://github.com/ampproject/amphtml/blob/master/extensions/' +
'amp-bind/amp-bind.md',
},
];

if (getMode().localDev) {
Expand Down

0 comments on commit 4b3dd8b

Please sign in to comment.