Implement shouldComponentUpdate for LinesComponent

We accumulate pending changes and pass them to the lines and the gutter
to help them determine whether to update. The lines only update if the
visible row range changed or if there was a change in the visible row
range.
This commit is contained in:
Nathan Sobo
2014-04-16 12:19:18 -06:00
parent d678f367db
commit 5a9a3c62e1
4 changed files with 21 additions and 19 deletions

View File

@@ -1,6 +1,6 @@
React = require 'react'
{div, span} = require 'reactionary'
{debounce, isEqualForProperties, multiplyString} = require 'underscore-plus'
{debounce, isEqual, isEqualForProperties, multiplyString} = require 'underscore-plus'
{$$} = require 'space-pen'
DummyLineNode = $$(-> @div className: 'line', style: 'position: absolute; visibility: hidden;', => @span 'x')[0]
@@ -28,6 +28,15 @@ LinesComponent = React.createClass
@measuredLines = new WeakSet
@updateModelDimensions()
shouldComponentUpdate: (newProps) ->
return true unless isEqualForProperties(newProps, @props, 'visibleRowRange', 'fontSize', 'fontFamily', 'lineHeight', 'showIndentGuide')
{visibleRowRange, pendingChanges} = newProps
for change in pendingChanges
return true unless change.end <= visibleRowRange.start or visibleRowRange.end <= change.start
false
componentDidUpdate: (prevProps) ->
@updateModelDimensions() unless isEqualForProperties(prevProps, @props, 'fontSize', 'fontFamily', 'lineHeight')
@clearScopedCharWidths() unless isEqualForProperties(prevProps, @props, 'fontSize', 'fontFamily')