Encapsulate state update inside TextEditorPresenter#getState

This commit is contained in:
Antonio Scandurra
2015-02-28 09:25:53 +01:00
parent 290acb356c
commit 0dca5a5fcd
11 changed files with 288 additions and 303 deletions

View File

@@ -64,21 +64,21 @@ class TextEditorComponent
@scrollViewNode.classList.add('scroll-view')
@domNode.appendChild(@scrollViewNode)
@mountGutterComponent() if @presenter.state.gutter.visible
@mountGutterComponent() if @presenter.getState().gutter.visible
@hiddenInputComponent = new InputComponent(@presenter)
@hiddenInputComponent = new InputComponent
@scrollViewNode.appendChild(@hiddenInputComponent.domNode)
@linesComponent = new LinesComponent({@presenter, @hostElement, @useShadowDOM})
@scrollViewNode.appendChild(@linesComponent.domNode)
@horizontalScrollbarComponent = new ScrollbarComponent({@presenter, orientation: 'horizontal', onScroll: @onHorizontalScroll})
@horizontalScrollbarComponent = new ScrollbarComponent({orientation: 'horizontal', onScroll: @onHorizontalScroll})
@scrollViewNode.appendChild(@horizontalScrollbarComponent.domNode)
@verticalScrollbarComponent = new ScrollbarComponent({@presenter, orientation: 'vertical', onScroll: @onVerticalScroll})
@verticalScrollbarComponent = new ScrollbarComponent({orientation: 'vertical', onScroll: @onVerticalScroll})
@domNode.appendChild(@verticalScrollbarComponent.domNode)
@scrollbarCornerComponent = new ScrollbarCornerComponent(@presenter)
@scrollbarCornerComponent = new ScrollbarCornerComponent
@domNode.appendChild(@scrollbarCornerComponent.domNode)
@observeEditor()
@@ -103,10 +103,8 @@ class TextEditorComponent
window.removeEventListener 'resize', @requestHeightAndWidthMeasurement
updateSync: ->
@presenter.update()
@oldState ?= {}
@newState = @presenter.state
@newState = @presenter.getState()
cursorMoved = @cursorMoved
selectionChanged = @selectionChanged
@@ -130,18 +128,18 @@ class TextEditorComponent
else
@domNode.style.height = ''
if @presenter.state.gutter.visible
if @newState.gutter.visible
@mountGutterComponent() unless @gutterComponent?
@gutterComponent.updateSync()
@gutterComponent.updateSync(@newState)
else
@gutterComponent?.domNode?.remove()
@gutterComponent = null
@hiddenInputComponent.updateSync()
@linesComponent.updateSync()
@horizontalScrollbarComponent.updateSync()
@verticalScrollbarComponent.updateSync()
@scrollbarCornerComponent.updateSync()
@hiddenInputComponent.updateSync(@newState)
@linesComponent.updateSync(@newState)
@horizontalScrollbarComponent.updateSync(@newState)
@verticalScrollbarComponent.updateSync(@newState)
@scrollbarCornerComponent.updateSync(@newState)
if @editor.isAlive()
@updateParentViewFocusedClassIfNeeded()
@@ -154,7 +152,7 @@ class TextEditorComponent
@linesComponent.measureCharactersInNewLines() if @isVisible() and not @newState.content.scrollingVertically
mountGutterComponent: ->
@gutterComponent = new GutterComponent({@presenter, @editor, onMouseDown: @onGutterMouseDown})
@gutterComponent = new GutterComponent({@editor, onMouseDown: @onGutterMouseDown})
@domNode.insertBefore(@gutterComponent.domNode, @domNode.firstChild)
becameVisible: ->