Skip to content

Commit ee09d31

Browse files
committed
core registry: modernize code
1 parent 336f16d commit ee09d31

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

src/core/registry.js

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ import utils from "./utils";
2424
// below here modules that are only loaded
2525
import "./jquery-ext";
2626

27-
var log = logging.getLogger("registry"),
28-
disable_re = /patterns-disable=([^&]+)/g,
29-
dont_catch_re = /patterns-dont-catch/g,
30-
dont_catch = false,
31-
disabled = {},
32-
match;
27+
const log = logging.getLogger("registry");
28+
const disable_re = /patterns-disable=([^&]+)/g;
29+
const dont_catch_re = /patterns-dont-catch/g;
30+
const disabled = {};
31+
let dont_catch = false;
32+
let match;
3333

3434
while ((match = disable_re.exec(window.location.search)) !== null) {
3535
disabled[match[1]] = true;
@@ -41,14 +41,14 @@ while ((match = dont_catch_re.exec(window.location.search)) !== null) {
4141
log.info("I will not catch init exceptions");
4242
}
4343

44-
var registry = {
44+
const registry = {
4545
patterns: {},
4646
// as long as the registry is not initialized, pattern
4747
// registration just registers a pattern. Once init is called,
4848
// the DOM is scanned. After that registering a new pattern
4949
// results in rescanning the DOM only for this pattern.
5050
initialized: false,
51-
init: function registry_init() {
51+
init() {
5252
$(document).ready(function () {
5353
log.info(
5454
"loaded: " + Object.keys(registry.patterns).sort().join(", ")
@@ -59,13 +59,13 @@ var registry = {
5959
});
6060
},
6161

62-
clear: function clearRegistry() {
62+
clear() {
6363
// Removes all patterns from the registry. Currently only being
6464
// used in tests.
6565
this.patterns = {};
6666
},
6767

68-
transformPattern: function (name, content) {
68+
transformPattern(name, content) {
6969
/* Call the transform method on the pattern with the given name, if
7070
* it exists.
7171
*/
@@ -88,14 +88,14 @@ var registry = {
8888
}
8989
},
9090

91-
initPattern: function (name, el, trigger) {
91+
initPattern(name, el, trigger) {
9292
/* Initialize the pattern with the provided name and in the context
9393
* of the passed in DOM element.
9494
*/
95-
var $el = $(el);
96-
var pattern = registry.patterns[name];
95+
const $el = $(el);
96+
const pattern = registry.patterns[name];
9797
if (pattern.init) {
98-
var plog = logging.getLogger("pat." + name);
98+
const plog = logging.getLogger("pat." + name);
9999
if ($el.is(pattern.trigger)) {
100100
plog.debug("Initialising:", $el);
101101
try {
@@ -111,7 +111,7 @@ var registry = {
111111
}
112112
},
113113

114-
orderPatterns: function (patterns) {
114+
orderPatterns(patterns) {
115115
// XXX: Bit of a hack. We need the validation pattern to be
116116
// parsed and initiated before the inject pattern. So we make
117117
// sure here, that it appears first. Not sure what would be
@@ -127,15 +127,15 @@ var registry = {
127127
return patterns;
128128
},
129129

130-
scan: function registryScan(content, patterns, trigger) {
131-
var selectors = [],
132-
$match;
130+
scan(content, patterns, trigger) {
131+
const selectors = [];
132+
let $match;
133133
patterns = this.orderPatterns(
134134
patterns || Object.keys(registry.patterns)
135135
);
136136
patterns.forEach(_.partial(this.transformPattern, _, content));
137-
patterns = _.each(patterns, function (name) {
138-
var pattern = registry.patterns[name];
137+
patterns = _.each(patterns, (name) => {
138+
const pattern = registry.patterns[name];
139139
if (pattern.trigger) {
140140
selectors.unshift(pattern.trigger);
141141
}
@@ -157,8 +157,7 @@ var registry = {
157157
$("body").addClass("patterns-loaded");
158158
},
159159

160-
register: function registry_register(pattern, name) {
161-
var plugin_name;
160+
register(pattern, name) {
162161
name = name || pattern.name;
163162
if (!name) {
164163
log.error("Pattern lacks a name:", pattern);
@@ -174,12 +173,12 @@ var registry = {
174173

175174
// register pattern as jquery plugin
176175
if (pattern.jquery_plugin) {
177-
plugin_name = ("pat-" + name).replace(/-([a-zA-Z])/g, function (
178-
match,
179-
p1
180-
) {
181-
return p1.toUpperCase();
182-
});
176+
const plugin_name = ("pat-" + name).replace(
177+
/-([a-zA-Z])/g,
178+
function (match, p1) {
179+
return p1.toUpperCase();
180+
}
181+
);
183182
$.fn[plugin_name] = utils.jqueryPlugin(pattern);
184183
// BBB 2012-12-10 and also for Mockup patterns.
185184
$.fn[plugin_name.replace(/^pat/, "pattern")] = $.fn[plugin_name];

0 commit comments

Comments
 (0)