Skip to content

Commit 336f16d

Browse files
committed
core base: modernize code
1 parent 2a0e515 commit 336f16d

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

src/core/base.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ import Registry from "./registry";
1717
import logging from "./logging";
1818
import mockupParser from "./mockup-parser";
1919

20-
var log = logging.getLogger("Patternslib Base");
20+
const log = logging.getLogger("Patternslib Base");
2121

22-
var initBasePattern = function ($el, options, trigger) {
22+
const initBasePattern = function ($el, options, trigger) {
2323
if (!$el.jquery) {
2424
$el = $($el);
2525
}
26-
var name = this.prototype.name;
27-
var log = logging.getLogger("pat." + name);
28-
var pattern = $el.data("pattern-" + name);
26+
const name = this.prototype.name;
27+
const plog = logging.getLogger(`pat.${name}`);
28+
let pattern = $el.data(`pattern-${name}`);
2929
if (pattern === undefined && Registry.patterns[name]) {
3030
try {
3131
options =
@@ -34,14 +34,14 @@ var initBasePattern = function ($el, options, trigger) {
3434
: options;
3535
pattern = new Registry.patterns[name]($el, options, trigger);
3636
} catch (e) {
37-
log.error("Failed while initializing '" + name + "' pattern.", e);
37+
plog.error(`Failed while initializing ${name} pattern.`, e);
3838
}
39-
$el.data("pattern-" + name, pattern);
39+
$el.data(`pattern-${name}`, pattern);
4040
}
4141
return pattern;
4242
};
4343

44-
var Base = function ($el, options, trigger) {
44+
const Base = function ($el, options, trigger) {
4545
if (!$el.jquery) {
4646
$el = $($el);
4747
}
@@ -54,23 +54,23 @@ var Base = function ($el, options, trigger) {
5454

5555
Base.prototype = {
5656
constructor: Base,
57-
on: function (eventName, eventCallback) {
58-
this.$el.on(eventName + "." + this.name + ".patterns", eventCallback);
57+
on(eventName, eventCallback) {
58+
this.$el.on(`${eventName}.${this.name}.patterns`, eventCallback);
5959
},
60-
emit: function (eventName, args) {
60+
emit(eventName, args) {
6161
// args should be a list
6262
if (args === undefined) {
6363
args = [];
6464
}
65-
this.$el.trigger(eventName + "." + this.name + ".patterns", args);
65+
this.$el.trigger(`${eventName}.${this.name}.patterns`, args);
6666
},
6767
};
6868

6969
Base.extend = function (patternProps) {
7070
/* Helper function to correctly set up the prototype chain for new patterns.
7171
*/
72-
var parent = this;
73-
var child;
72+
const parent = this;
73+
let child;
7474

7575
// Check that the required configuration properties are given.
7676
if (!patternProps) {
@@ -120,10 +120,7 @@ Base.extend = function (patternProps) {
120120
);
121121
} else if (!patternProps.trigger) {
122122
log.warn(
123-
"The pattern '" +
124-
patternProps.name +
125-
"' does not " +
126-
"have a trigger attribute, it will not be registered."
123+
`The pattern ${patternProps.name} does not have a trigger attribute, it will not be registered.`
127124
);
128125
} else {
129126
Registry.register(child, patternProps.name);

0 commit comments

Comments
 (0)