mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-22 03:34:14 +00:00
refactor(dotSet): move dotSet & dotGet to exports
This commit is contained in:
parent
b449387cc0
commit
f1db2bf1d5
2 changed files with 36 additions and 29 deletions
40
dist/habitrpg-shared.js
vendored
40
dist/habitrpg-shared.js
vendored
|
|
@ -12306,10 +12306,31 @@ api = module.exports = {};
|
|||
|
||||
api.i18n = i18n;
|
||||
|
||||
$w = function(s) {
|
||||
$w = api.$w = function(s) {
|
||||
return s.split(' ');
|
||||
};
|
||||
|
||||
api.dotSet = function(obj, path, val) {
|
||||
var arr;
|
||||
arr = path.split('.');
|
||||
return _.reduce(arr, (function(_this) {
|
||||
return function(curr, next, index) {
|
||||
if ((arr.length - 1) === index) {
|
||||
curr[next] = val;
|
||||
}
|
||||
return curr[next] != null ? curr[next] : curr[next] = {};
|
||||
};
|
||||
})(this), obj);
|
||||
};
|
||||
|
||||
api.dotGet = function(obj, path) {
|
||||
return _.reduce(path.split('.'), ((function(_this) {
|
||||
return function(curr, next) {
|
||||
return curr != null ? curr[next] : void 0;
|
||||
};
|
||||
})(this)), obj);
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
------------------------------------------------------
|
||||
|
|
@ -13802,23 +13823,10 @@ api.wrap = function(user, main) {
|
|||
Angular sets object properties directly - in which case, this function will be used.
|
||||
*/
|
||||
dotSet: function(path, val) {
|
||||
var arr;
|
||||
arr = path.split('.');
|
||||
return _.reduce(arr, (function(_this) {
|
||||
return function(curr, next, index) {
|
||||
if ((arr.length - 1) === index) {
|
||||
curr[next] = val;
|
||||
}
|
||||
return curr[next] != null ? curr[next] : curr[next] = {};
|
||||
};
|
||||
})(this), user);
|
||||
return api.dotSet(user, path, val);
|
||||
},
|
||||
dotGet: function(path) {
|
||||
return _.reduce(path.split('.'), ((function(_this) {
|
||||
return function(curr, next) {
|
||||
return curr != null ? curr[next] : void 0;
|
||||
};
|
||||
})(this)), user);
|
||||
return api.dotGet(user, path);
|
||||
},
|
||||
randomDrop: function(modifiers, req) {
|
||||
var acceptableDrops, chance, drop, dropK, quest, rarity, task, _base, _base1, _base2, _name, _name1, _name2, _ref, _ref1;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,16 @@ api = module.exports = {}
|
|||
api.i18n = i18n
|
||||
|
||||
# little helper for large arrays of strings. %w"this that another" equivalent from Rails, I really miss that function
|
||||
$w = (s)->s.split(' ')
|
||||
$w = api.$w = (s)->s.split(' ')
|
||||
api.dotSet = (obj,path,val)->
|
||||
arr = path.split('.')
|
||||
_.reduce arr, (curr, next, index) =>
|
||||
if (arr.length - 1) == index
|
||||
curr[next] = val
|
||||
(curr[next] ?= {})
|
||||
, obj
|
||||
api.dotGet = (obj,path)->
|
||||
_.reduce path.split('.'), ((curr, next) => curr?[next]), obj
|
||||
|
||||
###
|
||||
------------------------------------------------------
|
||||
|
|
@ -975,18 +984,8 @@ api.wrap = (user, main=true) ->
|
|||
so that different consumers can implement setters their own way. Derby needs model.set(path, value) for example, where
|
||||
Angular sets object properties directly - in which case, this function will be used.
|
||||
###
|
||||
dotSet: (path, val) ->
|
||||
arr = path.split('.')
|
||||
_.reduce arr, (curr, next, index) =>
|
||||
if (arr.length - 1) == index
|
||||
curr[next] = val
|
||||
(curr[next] ?= {})
|
||||
, user
|
||||
|
||||
dotGet: (path) ->
|
||||
_.reduce path.split('.'), ((curr, next) => curr?[next]), user
|
||||
|
||||
|
||||
dotSet: (path, val)-> api.dotSet user,path,val
|
||||
dotGet: (path)-> api.dotGet user,path
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# Scoring
|
||||
|
|
|
|||
Loading…
Reference in a new issue