Convert local functions to arrow functions and remove `this` bindings
Change-Id: I2b0218bfe1688410c06c098723dd49580c74eeff
这个提交包含在:
父节点
55a4050b93
当前提交
7f2382ade7
|
@ -234,8 +234,7 @@ ve.ce.ContentBranchNode.prototype.getRenderedContents = function () {
|
|||
annotations: null,
|
||||
unicorns: null
|
||||
},
|
||||
buffer = '',
|
||||
node = this;
|
||||
buffer = '';
|
||||
|
||||
// Source mode optimization
|
||||
if ( this.getModel().getDocument().sourceMode ) {
|
||||
|
@ -248,7 +247,7 @@ ve.ce.ContentBranchNode.prototype.getRenderedContents = function () {
|
|||
return wrapper;
|
||||
}
|
||||
|
||||
function openAnnotation( annotation ) {
|
||||
var openAnnotation = ( annotation ) => {
|
||||
var ann;
|
||||
annotationsChanged = true;
|
||||
if ( buffer !== '' ) {
|
||||
|
@ -261,14 +260,14 @@ ve.ce.ContentBranchNode.prototype.getRenderedContents = function () {
|
|||
}
|
||||
// Create a new DOM node and descend into it
|
||||
annotation.store = store;
|
||||
ann = ve.ce.annotationFactory.create( annotation.getType(), annotation, node );
|
||||
ann = ve.ce.annotationFactory.create( annotation.getType(), annotation, this );
|
||||
ann.appendTo( current );
|
||||
annotationStack.push( ann );
|
||||
nodeStack.push( current );
|
||||
current = ann.getContentContainer();
|
||||
}
|
||||
};
|
||||
|
||||
function closeAnnotation() {
|
||||
var closeAnnotation = () => {
|
||||
var ann;
|
||||
annotationsChanged = true;
|
||||
if ( buffer !== '' ) {
|
||||
|
@ -283,7 +282,7 @@ ve.ce.ContentBranchNode.prototype.getRenderedContents = function () {
|
|||
ann = annotationStack.pop();
|
||||
ann.attachContents();
|
||||
current = nodeStack.pop();
|
||||
}
|
||||
};
|
||||
|
||||
var i, ilen;
|
||||
// Gather annotated HTML from the child nodes
|
||||
|
|
|
@ -1151,36 +1151,34 @@ ve.dm.Document.prototype.rebuildTree = function () {
|
|||
* @param {ve.dm.Node[]} removedNodes Removed nodes
|
||||
*/
|
||||
ve.dm.Document.prototype.updateNodesByType = function ( addedNodes, removedNodes ) {
|
||||
var doc = this;
|
||||
|
||||
function remove( node ) {
|
||||
var remove = ( node ) => {
|
||||
var type = node.getType(),
|
||||
nodes = doc.nodesByType[ type ] || [],
|
||||
nodes = this.nodesByType[ type ] || [],
|
||||
index = nodes.indexOf( node );
|
||||
|
||||
if ( index !== -1 ) {
|
||||
nodes.splice( index, 1 );
|
||||
if ( !nodes.length ) {
|
||||
delete doc.nodesByType[ type ];
|
||||
delete this.nodesByType[ type ];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function add( node ) {
|
||||
var add = ( node ) => {
|
||||
var type = node.getType(),
|
||||
nodes = doc.nodesByType[ type ] = doc.nodesByType[ type ] || [];
|
||||
nodes = this.nodesByType[ type ] = this.nodesByType[ type ] || [];
|
||||
|
||||
nodes.push( node );
|
||||
}
|
||||
};
|
||||
|
||||
function traverse( nodes, action ) {
|
||||
var traverse = ( nodes, action ) => {
|
||||
nodes.forEach( ( node ) => {
|
||||
if ( node.hasChildren() ) {
|
||||
node.traverse( action );
|
||||
}
|
||||
action( node );
|
||||
} );
|
||||
}
|
||||
};
|
||||
|
||||
traverse( removedNodes, remove );
|
||||
traverse( addedNodes, add );
|
||||
|
|
|
@ -251,28 +251,25 @@
|
|||
*/
|
||||
ve.dm.ModelRegistry.prototype.matchElement = function ( node, forceAboutGrouping, excludeTypes ) {
|
||||
var types,
|
||||
nodeName = node.nodeName.toLowerCase(),
|
||||
reg = this;
|
||||
nodeName = node.nodeName.toLowerCase();
|
||||
|
||||
function byRegistrationOrderDesc( a, b ) {
|
||||
return reg.registrationOrder[ b ] - reg.registrationOrder[ a ];
|
||||
}
|
||||
var byRegistrationOrderDesc = ( a, b ) => this.registrationOrder[ b ] - this.registrationOrder[ a ];
|
||||
|
||||
function matchTypeRegExps( type, tag, withFunc ) {
|
||||
var matchTypeRegExps = ( type, tag, withFunc ) => {
|
||||
var matchedModels = [],
|
||||
models = reg.modelsWithTypeRegExps[ +withFunc ];
|
||||
models = this.modelsWithTypeRegExps[ +withFunc ];
|
||||
for ( var j = 0; j < models.length; j++ ) {
|
||||
if ( excludeTypes && excludeTypes.indexOf( models[ j ] ) !== -1 ) {
|
||||
continue;
|
||||
}
|
||||
var matchTypes = reg.registry[ models[ j ] ].static.getMatchRdfaTypes();
|
||||
var matchTypes = this.registry[ models[ j ] ].static.getMatchRdfaTypes();
|
||||
for ( var k = 0; k < matchTypes.length; k++ ) {
|
||||
if (
|
||||
matchTypes[ k ] instanceof RegExp &&
|
||||
matchTypes[ k ].test( type ) &&
|
||||
(
|
||||
( tag === '' && reg.registry[ models[ j ] ].static.matchTagNames === null ) ||
|
||||
( reg.registry[ models[ j ] ].static.matchTagNames || [] ).indexOf( tag ) !== -1
|
||||
( tag === '' && this.registry[ models[ j ] ].static.matchTagNames === null ) ||
|
||||
( this.registry[ models[ j ] ].static.matchTagNames || [] ).indexOf( tag ) !== -1
|
||||
)
|
||||
) {
|
||||
matchedModels.push( models[ j ] );
|
||||
|
@ -280,9 +277,9 @@
|
|||
}
|
||||
}
|
||||
return matchedModels;
|
||||
}
|
||||
};
|
||||
|
||||
function allTypesAllowed( model ) {
|
||||
var allTypesAllowed = ( model ) => {
|
||||
var allowedTypes = model.static.getAllowedRdfaTypes();
|
||||
var matchTypes = model.static.getMatchRdfaTypes();
|
||||
|
||||
|
@ -312,60 +309,60 @@
|
|||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
function matchWithFunc( tag ) {
|
||||
var matchWithFunc = ( tag ) => {
|
||||
var queue = [],
|
||||
queue2 = [];
|
||||
var j;
|
||||
for ( j = 0; j < types.length; j++ ) {
|
||||
// Queue string matches and regexp matches separately
|
||||
queue = queue.concat( ve.getProp( reg.modelsByTypeAndTag, 1, types[ j ], tag ) || [] );
|
||||
queue = queue.concat( ve.getProp( this.modelsByTypeAndTag, 1, types[ j ], tag ) || [] );
|
||||
if ( excludeTypes ) {
|
||||
queue = OO.simpleArrayDifference( queue, excludeTypes );
|
||||
}
|
||||
queue2 = queue2.concat( matchTypeRegExps( types[ j ], tag, true ) );
|
||||
}
|
||||
// Filter out matches which contain types which aren't allowed
|
||||
queue = queue.filter( ( name ) => allTypesAllowed( reg.lookup( name ) ) );
|
||||
queue2 = queue2.filter( ( name ) => allTypesAllowed( reg.lookup( name ) ) );
|
||||
queue = queue.filter( ( name ) => allTypesAllowed( this.lookup( name ) ) );
|
||||
queue2 = queue2.filter( ( name ) => allTypesAllowed( this.lookup( name ) ) );
|
||||
if ( forceAboutGrouping ) {
|
||||
// Filter out matches that don't support about grouping
|
||||
queue = queue.filter( ( name ) => reg.registry[ name ].static.enableAboutGrouping );
|
||||
queue2 = queue2.filter( ( name ) => reg.registry[ name ].static.enableAboutGrouping );
|
||||
queue = queue.filter( ( name ) => this.registry[ name ].static.enableAboutGrouping );
|
||||
queue2 = queue2.filter( ( name ) => this.registry[ name ].static.enableAboutGrouping );
|
||||
}
|
||||
// Try string matches first, then regexp matches
|
||||
queue.sort( byRegistrationOrderDesc );
|
||||
queue2.sort( byRegistrationOrderDesc );
|
||||
queue = queue.concat( queue2 );
|
||||
for ( j = 0; j < queue.length; j++ ) {
|
||||
if ( reg.registry[ queue[ j ] ].static.matchFunction( node ) ) {
|
||||
if ( this.registry[ queue[ j ] ].static.matchFunction( node ) ) {
|
||||
return queue[ j ];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
function matchWithoutFunc( tag ) {
|
||||
var matchWithoutFunc = ( tag ) => {
|
||||
var queue = [],
|
||||
queue2 = [],
|
||||
winningName = null;
|
||||
var j;
|
||||
for ( j = 0; j < types.length; j++ ) {
|
||||
// Queue string and regexp matches separately
|
||||
queue = queue.concat( ve.getProp( reg.modelsByTypeAndTag, 0, types[ j ], tag ) || [] );
|
||||
queue = queue.concat( ve.getProp( this.modelsByTypeAndTag, 0, types[ j ], tag ) || [] );
|
||||
if ( excludeTypes ) {
|
||||
queue = OO.simpleArrayDifference( queue, excludeTypes );
|
||||
}
|
||||
queue2 = queue2.concat( matchTypeRegExps( types[ j ], tag, false ) );
|
||||
}
|
||||
// Filter out matches which contain types which aren't allowed
|
||||
queue = queue.filter( ( name ) => allTypesAllowed( reg.lookup( name ) ) );
|
||||
queue2 = queue2.filter( ( name ) => allTypesAllowed( reg.lookup( name ) ) );
|
||||
queue = queue.filter( ( name ) => allTypesAllowed( this.lookup( name ) ) );
|
||||
queue2 = queue2.filter( ( name ) => allTypesAllowed( this.lookup( name ) ) );
|
||||
if ( forceAboutGrouping ) {
|
||||
// Filter out matches that don't support about grouping
|
||||
queue = queue.filter( ( name ) => reg.registry[ name ].static.enableAboutGrouping );
|
||||
queue2 = queue2.filter( ( name ) => reg.registry[ name ].static.enableAboutGrouping );
|
||||
queue = queue.filter( ( name ) => this.registry[ name ].static.enableAboutGrouping );
|
||||
queue2 = queue2.filter( ( name ) => this.registry[ name ].static.enableAboutGrouping );
|
||||
}
|
||||
// Only try regexp matches if there are no string matches
|
||||
queue = queue.length > 0 ? queue : queue2;
|
||||
|
@ -373,13 +370,13 @@
|
|||
for ( j = 0; j < queue.length; j++ ) {
|
||||
if (
|
||||
winningName === null ||
|
||||
reg.registrationOrder[ winningName ] < reg.registrationOrder[ queue[ j ] ]
|
||||
this.registrationOrder[ winningName ] < this.registrationOrder[ queue[ j ] ]
|
||||
) {
|
||||
winningName = queue[ j ];
|
||||
}
|
||||
}
|
||||
return winningName;
|
||||
}
|
||||
};
|
||||
|
||||
types = [];
|
||||
if ( node.getAttribute ) {
|
||||
|
|
|
@ -135,13 +135,12 @@
|
|||
* @inheritdoc
|
||||
*/
|
||||
ve.init.sa.SafeStorage.prototype.clearExpired = function () {
|
||||
var storage = this;
|
||||
return this.getExpiryKeys().then( ( keys ) => $.Deferred( ( d ) => {
|
||||
requestIdleCallback( function iterate( deadline ) {
|
||||
var iterate = ( deadline ) => {
|
||||
while ( keys[ 0 ] !== undefined && deadline.timeRemaining() > MIN_WORK_TIME ) {
|
||||
var key = keys.shift();
|
||||
if ( storage.isExpired( key ) ) {
|
||||
storage.remove( key );
|
||||
if ( this.isExpired( key ) ) {
|
||||
this.remove( key );
|
||||
}
|
||||
}
|
||||
if ( keys[ 0 ] !== undefined ) {
|
||||
|
@ -150,7 +149,8 @@
|
|||
} else {
|
||||
return d.resolve();
|
||||
}
|
||||
} );
|
||||
};
|
||||
requestIdleCallback( iterate );
|
||||
} ) );
|
||||
};
|
||||
|
||||
|
|
|
@ -235,18 +235,17 @@ ve.ui.CompletionWidget.prototype.onMenuToggle = function ( visible ) {
|
|||
*/
|
||||
ve.ui.CompletionWidget.prototype.onModelSelect = function () {
|
||||
var range = this.getCompletionRange();
|
||||
var widget = this;
|
||||
|
||||
function countMatches() {
|
||||
var matches = widget.menu.getItems().length;
|
||||
if ( widget.header.getLabel() !== null ) {
|
||||
var countMatches = () => {
|
||||
var matches = this.menu.getItems().length;
|
||||
if ( this.header.getLabel() !== null ) {
|
||||
matches--;
|
||||
}
|
||||
if ( widget.action.constructor.static.alwaysIncludeInput ) {
|
||||
if ( this.action.constructor.static.alwaysIncludeInput ) {
|
||||
matches--;
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
};
|
||||
|
||||
if ( !range || range.isBackwards() || this.action.shouldAbandon( this.surfaceModel.getDocument().data.getText( false, range ), countMatches() ) ) {
|
||||
this.teardown();
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
* @param {string[]} eventNames List of event Names to listen to
|
||||
*/
|
||||
ve.EventSequencer = function VeEventSequencer( eventNames ) {
|
||||
var eventSequencer = this;
|
||||
this.$node = null;
|
||||
this.eventNames = eventNames;
|
||||
this.eventHandlers = {};
|
||||
|
@ -60,11 +59,7 @@ ve.EventSequencer = function VeEventSequencer( eventNames ) {
|
|||
* @param {string} name The event's name
|
||||
* @return {Function} An event handler
|
||||
*/
|
||||
function makeEventHandler( name ) {
|
||||
return function ( ev ) {
|
||||
return eventSequencer.onEvent( name, ev );
|
||||
};
|
||||
}
|
||||
var makeEventHandler = ( name ) => ( ev ) => this.onEvent( name, ev );
|
||||
|
||||
/**
|
||||
* @property {Object[]} Pending calls
|
||||
|
|
正在加载...
在新工单中引用