1- /*@flow weak*/
21import React , { Component } from 'react' ;
32import CodeMirror from 'codemirror' ;
4- import { connect } from 'react-redux' ;
3+ import { inject , observer } from 'mobx-react'
4+ import { dispatch } from 'store'
55import './addons' ;
66import dispatchCommand from '../../commands/dispatchCommand'
77import _ from 'lodash'
@@ -39,10 +39,10 @@ function getMode (tab) {
3939
4040const debounced = _ . debounce ( func => func ( ) , 1000 )
4141
42- @connect ( state => ( {
43- setting : state . SettingState . views . tabs . EDITOR ,
44- themeSetting : state . SettingState . views . tabs . THEME ,
42+ @inject ( state => ( {
43+ themeName : state . SettingState . settings . theme . syntax_theme . value ,
4544} ) )
45+ @observer
4646class CodeMirrorEditor extends Component {
4747 static defaultProps = {
4848 theme : 'default' ,
@@ -56,15 +56,14 @@ class CodeMirrorEditor extends Component {
5656 }
5757
5858 componentDidMount ( ) {
59- const { themeSetting, tab } = this . props ;
60- const themeConfig = themeSetting . items [ 1 ] . value
59+ const { themeName, tab } = this . props ;
6160 let editorInitialized = false
6261 // todo add other setting item from config
6362 if ( tab . editor ) {
6463 this . editor = tab . editor
6564 this . editorContainer . appendChild ( this . editor . getWrapperElement ( ) )
6665 } else {
67- this . editor = tab . editor = initializeEditor ( this . editorContainer , themeConfig )
66+ this . editor = tab . editor = initializeEditor ( this . editorContainer , themeName )
6867 editorInitialized = true
6968 }
7069 const editor = this . editor
@@ -100,7 +99,7 @@ class CodeMirrorEditor extends Component {
10099
101100 onChange = ( e ) => {
102101 if ( ! this . isChanging ) this . isChanging = true
103- const { tab, dispatch } = this . props ;
102+ const { tab } = this . props ;
104103 dispatch ( TabActions . updateTab ( {
105104 id : tab . id ,
106105 flags : { modified : true } ,
@@ -113,17 +112,17 @@ class CodeMirrorEditor extends Component {
113112 }
114113
115114 onFocus = ( ) => {
116- this . props . dispatch ( TabActions . activateTab ( this . props . tab . id ) )
115+ dispatch ( TabActions . activateTab ( this . props . tab . id ) )
117116 }
118117
119- componentWillReceiveProps ( { tab, themeSetting } ) {
118+ componentWillReceiveProps ( { tab, themeName } ) {
120119 if ( tab . flags . modified || ! this . editor || ! tab . content ) return
121120 if ( tab . content . body !== this . editor . getValue ( ) ) {
122121 this . editor . setValue ( tab . content . body )
123122 }
124123
125- const nextTheme = themeSetting . items [ 1 ] . value
126- const theme = this . props . themeSetting . items [ 1 ] . value
124+ const nextTheme = themeName
125+ const theme = this . props . themeName
127126 if ( theme !== nextTheme ) this . editor . setOption ( 'theme' , nextTheme )
128127 }
129128
@@ -142,35 +141,34 @@ class CodeMirrorEditor extends Component {
142141}
143142
144143
145- @connect ( state => ( {
146- setting : state . SettingState . views . tabs . EDITOR ,
147- themeSetting : state . SettingState . views . tabs . THEME ,
144+ @inject ( state => ( {
145+ themeName : state . SettingState . settings . theme . syntax_theme . value ,
148146} ) )
147+ @observer
149148class TablessCodeMirrorEditor extends Component {
150149 constructor ( props ) {
151150 super ( props )
152151 this . state = { }
153152 }
154153
155154 componentDidMount ( ) {
156- const { themeSetting, width, height } = this . props
157- const theme = themeSetting . items [ 1 ] . value
155+ const { themeName, width, height } = this . props
158156
159- this . editor = initializeEditor ( this . editorContainer , theme )
157+ this . editor = initializeEditor ( this . editorContainer , themeName )
160158 this . editor . focus ( )
161159 this . editor . on ( 'change' , this . onChange )
162160 }
163161
164162 onChange = ( e ) => {
165- this . props . dispatch ( TabActions . createTabInGroup ( this . props . tabGroupId , {
163+ dispatch ( TabActions . createTabInGroup ( this . props . tabGroupId , {
166164 flags : { modified : true } ,
167165 content : this . editor . getValue ( )
168166 } ) )
169167 }
170168
171- componentWillReceiveProps ( { themeSetting } ) {
172- const nextTheme = themeSetting . items [ 1 ] . value
173- const theme = this . props . themeSetting . items [ 1 ] . value
169+ componentWillReceiveProps ( { themeName } ) {
170+ const nextTheme = themeName
171+ const theme = this . props . themeName
174172 if ( theme !== nextTheme ) this . editor . setOption ( 'theme' , nextTheme )
175173 }
176174
0 commit comments