Skip to content

Commit eb87cc5

Browse files
author
tohosaku
committed
Remove "self"
1 parent d5ae104 commit eb87cc5

28 files changed

+622
-702
lines changed

src/core.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,23 +223,21 @@ export class JSONEditor {
223223
if (this.firing_change) return
224224
this.firing_change = true
225225

226-
const self = this
227-
228226
window.requestAnimationFrame(() => {
229-
self.firing_change = false
230-
if (!self.ready) return
227+
this.firing_change = false
228+
if (!this.ready) return
231229

232230
/* Validate and cache results */
233-
self.validation_results = self.validator.validate(self.root.getValue())
231+
this.validation_results = this.validator.validate(this.root.getValue())
234232

235-
if (self.options.show_errors !== 'never') {
236-
self.root.showValidationErrors(self.validation_results)
233+
if (this.options.show_errors !== 'never') {
234+
this.root.showValidationErrors(this.validation_results)
237235
} else {
238-
self.root.showValidationErrors([])
236+
this.root.showValidationErrors([])
239237
}
240238

241239
/* Fire change event */
242-
self.trigger('change')
240+
this.trigger('change')
243241
})
244242

245243
return this

src/editor.js

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,13 @@ export class AbstractEditor {
9292
return
9393
}
9494

95-
const self = this
9695
Object.keys(deps).forEach(dependency => {
97-
let path = self.path.split('.')
96+
let path = this.path.split('.')
9897
path[path.length - 1] = dependency
9998
path = path.join('.')
10099
const choices = deps[dependency]
101-
self.jsoneditor.watch(path, () => {
102-
self.checkDependency(path, choices)
100+
this.jsoneditor.watch(path, () => {
101+
this.checkDependency(path, choices)
103102
})
104103
})
105104
}
@@ -110,7 +109,6 @@ export class AbstractEditor {
110109
return
111110
}
112111

113-
const self = this
114112
const editor = this.jsoneditor.getEditor(path)
115113
const value = editor ? editor.getValue() : undefined
116114
const previousStatus = this.dependenciesFulfilled
@@ -121,7 +119,7 @@ export class AbstractEditor {
121119
} else if (Array.isArray(choices)) {
122120
choices.some(choice => {
123121
if (value === choice) {
124-
self.dependenciesFulfilled = true
122+
this.dependenciesFulfilled = true
125123
return true
126124
}
127125
})
@@ -134,10 +132,10 @@ export class AbstractEditor {
134132
return false
135133
}
136134
if (!hasOwnProperty(value, key) || choices[key] !== value[key]) {
137-
self.dependenciesFulfilled = false
135+
this.dependenciesFulfilled = false
138136
return true
139137
}
140-
self.dependenciesFulfilled = true
138+
this.dependenciesFulfilled = true
141139
})
142140
}
143141
} else if (typeof choices === 'string' || typeof choices === 'number') {
@@ -169,17 +167,17 @@ export class AbstractEditor {
169167

170168
setOptInCheckbox (header) {
171169
/* the active/deactive checbox control. */
172-
const self = this
170+
173171
this.optInCheckbox = document.createElement('input')
174172
this.optInCheckbox.setAttribute('type', 'checkbox')
175173
this.optInCheckbox.setAttribute('style', 'margin: 0 10px 0 0;')
176174
this.optInCheckbox.classList.add('json-editor-opt-in')
177175

178176
this.optInCheckbox.addEventListener('click', () => {
179-
if (self.isActive()) {
180-
self.deactivate()
177+
if (this.isActive()) {
178+
this.deactivate()
181179
} else {
182-
self.activate()
180+
this.activate()
183181
}
184182
})
185183

@@ -211,21 +209,19 @@ export class AbstractEditor {
211209
}
212210

213211
setupWatchListeners () {
214-
const self = this
215-
216212
/* Watched fields */
217213
this.watched = {}
218214
if (this.schema.vars) this.schema.watch = this.schema.vars
219215
this.watched_values = {}
220216
this.watch_listener = () => {
221-
if (self.refreshWatchedFieldValues()) {
222-
self.onWatchedFieldChange()
217+
if (this.refreshWatchedFieldValues()) {
218+
this.onWatchedFieldChange()
223219
}
224220
}
225221

226222
if (hasOwnProperty(this.schema, 'watch')) {
227223
let path; let pathParts; let first; let root; let adjustedPath
228-
const myPath = self.container.getAttribute('data-schemapath')
224+
const myPath = this.container.getAttribute('data-schemapath')
229225

230226
Object.keys(this.schema.watch).forEach(name => {
231227
path = this.schema.watch[name]
@@ -234,23 +230,23 @@ export class AbstractEditor {
234230
pathParts = [path[0]].concat(path[1].split('.'))
235231
} else {
236232
pathParts = path.split('.')
237-
if (!self.theme.closest(self.container, `[data-schemaid="${pathParts[0]}"]`)) pathParts.unshift('#')
233+
if (!this.theme.closest(this.container, `[data-schemaid="${pathParts[0]}"]`)) pathParts.unshift('#')
238234
}
239235
first = pathParts.shift()
240236

241-
if (first === '#') first = self.jsoneditor.schema.id || 'root'
237+
if (first === '#') first = this.jsoneditor.schema.id || 'root'
242238

243239
/* Find the root node for this template variable */
244-
root = self.theme.closest(self.container, `[data-schemaid="${first}"]`)
240+
root = this.theme.closest(this.container, `[data-schemaid="${first}"]`)
245241
if (!root) throw new Error(`Could not find ancestor node with id ${first}`)
246242

247243
/* Keep track of the root node and path for use when rendering the template */
248244
adjustedPath = `${root.getAttribute('data-schemapath')}.${pathParts.join('.')}`
249245

250-
if (myPath.startsWith(adjustedPath)) self.watchLoop = true
251-
self.jsoneditor.watch(adjustedPath, self.watch_listener)
246+
if (myPath.startsWith(adjustedPath)) this.watchLoop = true
247+
this.jsoneditor.watch(adjustedPath, this.watch_listener)
252248

253-
self.watched[name] = adjustedPath
249+
this.watched[name] = adjustedPath
254250
})
255251
}
256252

@@ -402,13 +398,12 @@ export class AbstractEditor {
402398
if (!this.watched_values) return
403399
const watched = {}
404400
let changed = false
405-
const self = this
406401

407402
if (this.watched) {
408403
Object.keys(this.watched).forEach(name => {
409-
const editor = self.jsoneditor.getEditor(this.watched[name])
404+
const editor = this.jsoneditor.getEditor(this.watched[name])
410405
const val = editor ? editor.getValue() : null
411-
if (self.watched_values[name] !== val) changed = true
406+
if (this.watched_values[name] !== val) changed = true
412407
watched[name] = val
413408
})
414409
}
@@ -504,10 +499,9 @@ export class AbstractEditor {
504499
}
505500

506501
destroy () {
507-
const self = this
508502
this.unregister(this)
509503
if (this.watched) {
510-
Object.values(this.watched).forEach(adjustedPath => self.jsoneditor.unwatch(adjustedPath, self.watch_listener))
504+
Object.values(this.watched).forEach(adjustedPath => this.jsoneditor.unwatch(adjustedPath, this.watch_listener))
511505
}
512506

513507
this.watched = null

src/editors/ace.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export class AceEditor extends StringEditor {
1919
}
2020

2121
afterInputReady () {
22-
const self = this
2322
let options
2423

2524
if (window.ace) {
@@ -56,13 +55,13 @@ export class AceEditor extends StringEditor {
5655

5756
/* Listen for changes */
5857
this.ace_editor_instance.on('change', () => {
59-
self.input.value = self.ace_editor_instance.getValue()
60-
self.refreshValue()
61-
self.is_dirty = true
62-
self.onChange(true)
58+
this.input.value = this.ace_editor_instance.getValue()
59+
this.refreshValue()
60+
this.is_dirty = true
61+
this.onChange(true)
6362
})
6463

65-
this.theme.afterInputReady(self.input)
64+
this.theme.afterInputReady(this.input)
6665
} else super.afterInputReady() /* Library not loaded, so just treat this as a string */
6766
}
6867

0 commit comments

Comments
 (0)