* Applies expression results to a single BoundElementDef. * @param {!Element} element * @param {!Array<{boundProperty: !BoundPropertyDef, newValue: BindExpressionResultDef}>} updates * @return {!Promise}
(element, updates)
| 1217 | * @return {!Promise} |
| 1218 | */ |
| 1219 | applyUpdatesToElement_(element, updates) { |
| 1220 | if (updates.length === 0) { |
| 1221 | return Promise.resolve(); |
| 1222 | } |
| 1223 | return this.mutator_.mutateElement(element, () => { |
| 1224 | const mutations = map(); |
| 1225 | let width, height; |
| 1226 | |
| 1227 | updates.forEach((update) => { |
| 1228 | const {boundProperty, newValue} = update; |
| 1229 | const {property} = boundProperty; |
| 1230 | const mutation = this.applyBinding_(boundProperty, element, newValue); |
| 1231 | |
| 1232 | if (mutation) { |
| 1233 | mutations[mutation.name] = mutation.value; |
| 1234 | if (property == 'width') { |
| 1235 | width = isFiniteNumber(newValue) ? Number(newValue) : width; |
| 1236 | } else if (property == 'height') { |
| 1237 | height = isFiniteNumber(newValue) ? Number(newValue) : height; |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | this.dispatchFormValueChangeEventIfNecessary_(element, property); |
| 1242 | }); |
| 1243 | |
| 1244 | if (width !== undefined || height !== undefined) { |
| 1245 | // request without scheduling vsync pass since `mutateElement()` |
| 1246 | // will schedule a pass after a short delay anyways. |
| 1247 | this.mutator_.forceChangeSize(element, height, width); |
| 1248 | } |
| 1249 | |
| 1250 | if (typeof element.mutatedAttributesCallback === 'function') { |
| 1251 | // Prevent an exception in the callback from interrupting execution, |
| 1252 | // instead wrap in user error and give a helpful message. |
| 1253 | try { |
| 1254 | element.mutatedAttributesCallback(mutations); |
| 1255 | } catch (e) { |
| 1256 | const error = user().createError( |
| 1257 | '%s: Applying expression results (%s) failed with error,', |
| 1258 | TAG, |
| 1259 | JSON.stringify(mutations), |
| 1260 | e |
| 1261 | ); |
| 1262 | this.reportError_(error, element); |
| 1263 | } |
| 1264 | } |
| 1265 | }); |
| 1266 | } |
| 1267 | |
| 1268 | /** |
| 1269 | * Dispatches an `AmpEvents_Enum.FORM_VALUE_CHANGE` if the element's changed |
no test coverage detected