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

📖 Fix experiment-related sample code in documentation #21031

Merged
merged 5 commits into from Feb 25, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 10 additions & 9 deletions contributing/building-an-amp-extension.md
Expand Up @@ -655,7 +655,8 @@ And then protecting your code with a check `isExperimentOn(win,
'amp-my-element')` and only execute your code when it is on.

```javascript
import {isExperimentOn} from '../src/experiments';
import {isExperimentOn} from '../../../src/experiments';
import {user} from '../../../src/log';

/** @const */
const EXPERIMENT = 'amp-my-element';
Expand All @@ -679,20 +680,20 @@ Class AmpMyElement extends AMP.BaseElement {

/** @override */
buildCallback() {
if (!isExperimentOn(this.getWin(), EXPERIMENT)) {
user.warn('Experiment %s is not turned on.', EXPERIMENT);
return;
}
if(!isExperimentOn(this.win, 'amp-my-element')) {
gmajoulet marked this conversation as resolved.
Show resolved Hide resolved
user().warn(TAG, `Experiment ${EXPERIMENT} is not turned on.`);
return();
gmajoulet marked this conversation as resolved.
Show resolved Hide resolved
}
gmajoulet marked this conversation as resolved.
Show resolved Hide resolved
// get attributes, assertions of values, assign instance variables.
// build lightweight dom and append to this.element.
}

/** @override */
layoutCallback() {
if (!isExperimentOn(this.getWin(), EXPERIMENT)) {
user.warn('Experiment %s is not turned on.', EXPERIMENT);
return;
}
if(!isExperimentOn(this.win, 'amp-my-element')) {
user().warn(TAG, `Experiment ${EXPERIMENT} is not turned on.`);
return();
}
// actually load your resource or render more expensive resources.
}
}
Expand Down