Skip to content

Commit bd898be

Browse files
authored
Merge pull request jdorn#691 from tohosaku/update_standard
Use Arrow function and Remove "self"
2 parents 2c5ed70 + f33e6c0 commit bd898be

40 files changed

+1759
-2070
lines changed

package-lock.json

Lines changed: 858 additions & 985 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,10 @@
8383
"null-loader": "^3.0.0",
8484
"postcss-loader": "^3.0.0",
8585
"puppeteer": "^1.20.0",
86-
"puppeteer-firefox": "^0.5.1",
8786
"remove-strict-webpack-plugin": "^0.1.2",
88-
"requirejs": "^2.3.6",
8987
"sceditor": "^2.1.3",
9088
"sinon": "^8.1.1",
91-
"standard": "^11.0.1",
89+
"standard": "^14.3.3",
9290
"style-loader": "^1.1.3",
9391
"webpack": "^4.41.6",
9492
"webpack-cli": "^3.3.11",

src/core.js

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { editors } from './editors/index.js'
55
import { templates } from './templates/index.js'
66
import { iconlibs } from './iconlibs/index.js'
77
import { themes } from './themes/index.js'
8-
import { extend, each, getShadowParent } from './utilities.js'
8+
import { extend, getShadowParent, hasOwnProperty } from './utilities.js'
99

1010
export class JSONEditor {
1111
constructor (element, options = {}) {
@@ -74,7 +74,7 @@ export class JSONEditor {
7474
this.root.postBuild()
7575

7676
/* Starting data */
77-
if (this.options.hasOwnProperty('startval')) this.root.setValue(this.options.startval)
77+
if (hasOwnProperty(this.options, 'startval')) this.root.setValue(this.options.startval)
7878

7979
this.validation_results = this.validator.validate(this.root.getValue())
8080
this.root.showValidationErrors(this.validation_results)
@@ -191,24 +191,18 @@ export class JSONEditor {
191191
}
192192

193193
getEditorsRules () {
194-
const rules = {}
195-
196-
each(JSONEditor.defaults.editors, (i, editorClass) => editorClass.rules && extend(rules, editorClass.rules))
197-
198-
return rules
194+
const extendRule = (rules, editorClass) => editorClass.rules ? extend(rules, editorClass.rules) : rules
195+
return Object.values(JSONEditor.defaults.editors).reduce(extendRule, {})
199196
}
200197

201198
getEditorClass (schema) {
202199
let classname
203200

204201
schema = this.expandSchema(schema)
205202

206-
each(JSONEditor.defaults.resolvers, (i, resolver) => {
207-
const tmp = resolver(schema)
208-
if (tmp && JSONEditor.defaults.editors[tmp]) {
209-
classname = tmp
210-
return false
211-
}
203+
JSONEditor.defaults.resolvers.find(resolver => {
204+
classname = resolver(schema)
205+
return classname && JSONEditor.defaults.editors[classname]
212206
})
213207

214208
if (!classname) throw new Error(`Unknown editor for schema ${JSON.stringify(schema)}`)
@@ -229,23 +223,21 @@ export class JSONEditor {
229223
if (this.firing_change) return
230224
this.firing_change = true
231225

232-
const self = this
233-
234226
window.requestAnimationFrame(() => {
235-
self.firing_change = false
236-
if (!self.ready) return
227+
this.firing_change = false
228+
if (!this.ready) return
237229

238230
/* Validate and cache results */
239-
self.validation_results = self.validator.validate(self.root.getValue())
231+
this.validation_results = this.validator.validate(this.root.getValue())
240232

241-
if (self.options.show_errors !== 'never') {
242-
self.root.showValidationErrors(self.validation_results)
233+
if (this.options.show_errors !== 'never') {
234+
this.root.showValidationErrors(this.validation_results)
243235
} else {
244-
self.root.showValidationErrors([])
236+
this.root.showValidationErrors([])
245237
}
246238

247239
/* Fire change event */
248-
self.trigger('change')
240+
this.trigger('change')
249241
})
250242

251243
return this
@@ -374,28 +366,24 @@ export class JSONEditor {
374366
const sheet = styleTag.sheet ? styleTag.sheet : styleTag.styleSheet
375367
const qualifier = this.element.nodeName.toLowerCase()
376368

377-
for (var selector in rules) {
378-
if (!rules.hasOwnProperty(selector)) continue
379-
var sel = qualifier + '[data-theme="' + themeName + '"] ' + selector
369+
Object.keys(rules).forEach(selector => {
370+
const sel = `${qualifier}[data-theme="${themeName}"] ${selector}`
380371

381372
// all browsers, except IE before version 9
382373
if (sheet.insertRule) sheet.insertRule(sel + ' {' + decodeURIComponent(rules[selector]) + '}', 0)
383374
// Internet Explorer before version 9
384375
else if (sheet.addRule) sheet.addRule(sel, decodeURIComponent(rules[selector]), 0)
385-
}
376+
})
386377
}
387378

388379
addNewStyleRulesToShadowRoot (themeName, rules, shadowRoot) {
389380
const qualifier = this.element.nodeName.toLowerCase()
390381
let cssText = ''
391382

392-
for (var selector in rules) {
393-
if (!rules.hasOwnProperty(selector)) continue
394-
var sel = qualifier + '[data-theme="' + themeName + '"] ' + selector
395-
383+
Object.keys(rules).forEach(selector => {
384+
const sel = `${qualifier}[data-theme="${themeName}"] ${selector}`
396385
cssText += sel + ' {' + decodeURIComponent(rules[selector]) + '}' + '\n'
397-
}
398-
386+
})
399387
const styleSheet = new CSSStyleSheet()
400388
styleSheet.replaceSync(cssText)
401389
shadowRoot.adoptedStyleSheets = [...shadowRoot.adoptedStyleSheets, styleSheet]

src/defaults.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { each } from './utilities.js'
21
import { resolvers } from './resolvers.js'
32

43
/* default theme */
@@ -252,7 +251,7 @@ languages.en = {
252251
}
253252

254253
/* Default per-editor options */
255-
each(editors, (i, editor) => { editors[i].options = editor.options || {} })
254+
Object.entries(editors).forEach(([i, editor]) => { editors[i].options = editor.options || {} })
256255

257256
/* Default upload handler */
258257
function upload (type, file, cbs) {

0 commit comments

Comments
 (0)