Skip to content

Commit

Permalink
📖 Fix experiment-related sample code in documentation (#21031)
Browse files Browse the repository at this point in the history
* Replace user.warn() with userAssert in accordance with gulp test checks

* Replace userAssert() with correct usage of user().warn() to make update more similar to the original spirit of the example

* Move comment to new line

* manual lint

* Replace user().warn() with userAssert
  • Loading branch information
caroqliu authored and cvializ committed Feb 25, 2019
1 parent 528721a commit a691335
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 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 {userAssert} from '../../../src/log';

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

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

0 comments on commit a691335

Please sign in to comment.