mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-13 01:15:47 +01:00
minified settings-framework wrapper-length
This commit is contained in:
@@ -271,9 +271,9 @@ define(function () {
|
|||||||
@param callback The callback to call when done.
|
@param callback The callback to call when done.
|
||||||
*/
|
*/
|
||||||
persistSettings: function (hash, settings, notify, callback) {
|
persistSettings: function (hash, settings, notify, callback) {
|
||||||
if (settings != null && settings._settings != null && typeof settings._settings !== 'string') {
|
if (settings != null && settings._ != null && typeof settings._ !== 'string') {
|
||||||
settings = helper.deepClone(settings);
|
settings = helper.deepClone(settings);
|
||||||
settings._settings = JSON.stringify(settings._settings);
|
settings._ = JSON.stringify(settings._);
|
||||||
}
|
}
|
||||||
socket.emit('admin.settings.set', {
|
socket.emit('admin.settings.set', {
|
||||||
hash: hash,
|
hash: hash,
|
||||||
@@ -307,7 +307,7 @@ define(function () {
|
|||||||
*/
|
*/
|
||||||
use: function (settings) {
|
use: function (settings) {
|
||||||
try {
|
try {
|
||||||
settings._settings = JSON.parse(settings._settings);
|
settings._ = JSON.parse(settings._);
|
||||||
} catch (_error) {}
|
} catch (_error) {}
|
||||||
Settings.cfg = settings;
|
Settings.cfg = settings;
|
||||||
}
|
}
|
||||||
@@ -324,8 +324,8 @@ define(function () {
|
|||||||
@returns Object The settings.
|
@returns Object The settings.
|
||||||
*/
|
*/
|
||||||
get: function () {
|
get: function () {
|
||||||
if (Settings.cfg != null && Settings.cfg._settings !== void 0) {
|
if (Settings.cfg != null && Settings.cfg._ !== void 0) {
|
||||||
return Settings.cfg._settings;
|
return Settings.cfg._;
|
||||||
}
|
}
|
||||||
return Settings.cfg;
|
return Settings.cfg;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -26,16 +26,16 @@ function trim(obj1, obj2) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function mergeSettings(cfg, defCfg) {
|
function mergeSettings(cfg, defCfg) {
|
||||||
if (typeof cfg._settings !== typeof defCfg || typeof defCfg !== 'object') {
|
if (typeof cfg._ !== typeof defCfg || typeof defCfg !== 'object') {
|
||||||
cfg._settings = defCfg;
|
cfg._ = defCfg;
|
||||||
} else {
|
} else {
|
||||||
expandObjBy(cfg._settings, defCfg);
|
expandObjBy(cfg._, defCfg);
|
||||||
trim(cfg._settings, defCfg);
|
trim(cfg._, defCfg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
A class to manage Objects saved in {@link meta.settings} within property "_settings".
|
A class to manage Objects saved in {@link meta.settings} within property "_".
|
||||||
Constructor, synchronizes the settings and repairs them if version differs.
|
Constructor, synchronizes the settings and repairs them if version differs.
|
||||||
@param hash The hash to use for {@link meta.settings}.
|
@param hash The hash to use for {@link meta.settings}.
|
||||||
@param version The version of the settings, used to determine whether the saved settings may be corrupt.
|
@param version The version of the settings, used to determine whether the saved settings may be corrupt.
|
||||||
@@ -71,8 +71,8 @@ Settings.prototype.sync = function (callback) {
|
|||||||
var _this = this;
|
var _this = this;
|
||||||
meta.settings.get(this.hash, function (err, settings) {
|
meta.settings.get(this.hash, function (err, settings) {
|
||||||
try {
|
try {
|
||||||
if (settings._settings) {
|
if (settings._) {
|
||||||
settings._settings = JSON.parse(settings._settings);
|
settings._ = JSON.parse(settings._);
|
||||||
}
|
}
|
||||||
} catch (_error) {}
|
} catch (_error) {}
|
||||||
_this.cfg = settings;
|
_this.cfg = settings;
|
||||||
@@ -87,15 +87,12 @@ Settings.prototype.sync = function (callback) {
|
|||||||
@param callback Gets called when done.
|
@param callback Gets called when done.
|
||||||
*/
|
*/
|
||||||
Settings.prototype.persist = function (callback) {
|
Settings.prototype.persist = function (callback) {
|
||||||
var conf = this.cfg._settings,
|
var conf = this.cfg._,
|
||||||
_this = this;
|
_this = this;
|
||||||
if (typeof conf === 'object') {
|
if (typeof conf === 'object') {
|
||||||
conf = JSON.stringify(conf);
|
conf = JSON.stringify(conf);
|
||||||
}
|
}
|
||||||
meta.settings.set(this.hash, {
|
meta.settings.set(this.hash, this.createWrapper(this.cfg.v, conf), function () {
|
||||||
_settings: conf,
|
|
||||||
version: this.cfg.version
|
|
||||||
}, function () {
|
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === 'function') {
|
||||||
callback.apply(_this, arguments || []);
|
callback.apply(_this, arguments || []);
|
||||||
}
|
}
|
||||||
@@ -110,7 +107,7 @@ Settings.prototype.persist = function (callback) {
|
|||||||
@returns Object The setting to be used.
|
@returns Object The setting to be used.
|
||||||
*/
|
*/
|
||||||
Settings.prototype.get = function (key, def) {
|
Settings.prototype.get = function (key, def) {
|
||||||
var obj = this.cfg._settings,
|
var obj = this.cfg._,
|
||||||
parts = (key || '').split('.'),
|
parts = (key || '').split('.'),
|
||||||
part;
|
part;
|
||||||
for (var i = 0; i < parts.length; i++) {
|
for (var i = 0; i < parts.length; i++) {
|
||||||
@@ -148,8 +145,8 @@ Settings.prototype.getWrapper = function () {
|
|||||||
*/
|
*/
|
||||||
Settings.prototype.createWrapper = function (version, settings) {
|
Settings.prototype.createWrapper = function (version, settings) {
|
||||||
return {
|
return {
|
||||||
version: version,
|
v: version,
|
||||||
_settings: settings
|
_: settings
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -168,11 +165,11 @@ Settings.prototype.createDefaultWrapper = function () {
|
|||||||
*/
|
*/
|
||||||
Settings.prototype.set = function (key, val) {
|
Settings.prototype.set = function (key, val) {
|
||||||
var part, obj, parts;
|
var part, obj, parts;
|
||||||
this.cfg.version = this.version;
|
this.cfg.v = this.version;
|
||||||
if (val == null || !key) {
|
if (val == null || !key) {
|
||||||
this.cfg._settings = val || key;
|
this.cfg._ = val || key;
|
||||||
} else {
|
} else {
|
||||||
obj = this.cfg._settings;
|
obj = this.cfg._;
|
||||||
parts = key.split('.');
|
parts = key.split('.');
|
||||||
for (var i = 0, _len = parts.length - 1; i < _len; i++) {
|
for (var i = 0, _len = parts.length - 1; i < _len; i++) {
|
||||||
if (part = parts[i]) {
|
if (part = parts[i]) {
|
||||||
@@ -202,13 +199,13 @@ Settings.prototype.reset = function (callback) {
|
|||||||
@param force Whether to update and persist the settings even if the versions ara equal.
|
@param force Whether to update and persist the settings even if the versions ara equal.
|
||||||
*/
|
*/
|
||||||
Settings.prototype.checkStructure = function (callback, force) {
|
Settings.prototype.checkStructure = function (callback, force) {
|
||||||
if (!force && this.cfg.version === this.version) {
|
if (!force && this.cfg.v === this.version) {
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === 'function') {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mergeSettings(this.cfg, this.defCfg);
|
mergeSettings(this.cfg, this.defCfg);
|
||||||
this.cfg.version = this.version;
|
this.cfg.v = this.version;
|
||||||
this.persist(callback);
|
this.persist(callback);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
Reference in New Issue
Block a user