From a6913351f5cddf1b15098f275a2b71fdaaf4bf65 Mon Sep 17 00:00:00 2001 From: Caroline Liu <10456171+caroqliu@users.noreply.github.com> Date: Mon, 25 Feb 2019 14:51:35 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=96=20Fix=20experiment-related=20sampl?= =?UTF-8?q?e=20code=20in=20documentation=20(#21031)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- contributing/building-an-amp-extension.md | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/contributing/building-an-amp-extension.md b/contributing/building-an-amp-extension.md index da1610841042..b6098072f8f7 100644 --- a/contributing/building-an-amp-extension.md +++ b/contributing/building-an-amp-extension.md @@ -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'; @@ -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. } }