mediawiki-extensions-Visual.../modules/ve/dm/nodes/ve.dm.GeneratedContentNode.js
Roan Kattouw 7673a39878 Support previews and concurrent updates in ce.GeneratedContentNode
GeneratedContentNode didn't track concurrent updates at all, so a
race condition was possible: if the node was updated a second time
before the first update had been rendered, the second update might
render first and then be overwritten by the other one.

To prevent this, we track the promise associated with the current
render. If a new update is launched while a previous one is still
pending we attempt to abort the old one by calling .abort() on it,
and ignore any future resolution or rejection from it.

Also allow rerenders based on non-model data by calling
.update( { config object } );

Change-Id: I8feefd9e8fb6c41d06b8b20131e3be5e37954e83
2013-08-08 11:34:50 +08:00

34 lines
1 KiB
JavaScript

/*!
* VisualEditor DataModel GeneratedContentNode class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* DataModel generated content node.
*
* @class
* @abstract
* @constructor
* @param {number} [length] Length of content data in document; ignored and overridden to 0
* @param {Object} [element] Reference to element in linear model
*/
ve.dm.GeneratedContentNode = function VeDmGeneratedContentNode() {
};
/* Static methods */
ve.dm.GeneratedContentNode.static = {};
/**
* Store HTML of DOM elements, hashed on data element
* @param {Object} dataElement Data element
* @param {HTMLElement[]} domElements DOM elements
* @param {ve.dm.IndexValueStore} store Index-value store
* @returns {number} Index of stored data
*/
ve.dm.GeneratedContentNode.static.storeDomElements = function ( dataElement, domElements, store ) {
var hash = ve.getHash( [ this.getHashObject( dataElement ), undefined ] );
return store.index( domElements, hash );
};