refactor: move randomVal to a lib

This commit is contained in:
Blade Barringer
2016-09-26 08:14:18 -05:00
parent 331993c1df
commit 913cb16638
9 changed files with 13 additions and 15 deletions

View File

@@ -1,7 +1,6 @@
import handleTwoHanded from './handleTwoHanded';
import predictableRandom from './predictableRandom';
import crit from './crit';
import randomVal from './randomVal';
import randomDrop from './randomDrop';
import autoAllocate from './autoAllocate';
import updateStats from './updateStats';
@@ -11,7 +10,6 @@ module.exports = {
handleTwoHanded,
predictableRandom,
crit,
randomVal,
randomDrop,
autoAllocate,
updateStats,

View File

@@ -3,7 +3,7 @@ import content from '../content/index';
import i18n from '../i18n';
import { daysSince } from '../cron';
import { diminishingReturns } from '../statHelpers';
import randomVal from './randomVal';
import randomVal from '../libs/randomVal';
// TODO This is only used on the server
// move to user model as an instance method?

View File

@@ -91,12 +91,14 @@ api.statsComputed = statsComputed;
import shops from './libs/shops';
api.shops = shops;
import randomVal from './libs/randomVal';
api.randomVal = randomVal;
import autoAllocate from './fns/autoAllocate';
import crit from './fns/crit';
import handleTwoHanded from './fns/handleTwoHanded';
import predictableRandom from './fns/predictableRandom';
import randomDrop from './fns/randomDrop';
import randomVal from './fns/randomVal';
import resetGear from './fns/resetGear';
import ultimateGear from './fns/ultimateGear';
import updateStats from './fns/updateStats';
@@ -107,7 +109,6 @@ api.fns = {
handleTwoHanded,
predictableRandom,
randomDrop,
randomVal,
resetGear,
ultimateGear,
updateStats,

View File

@@ -1,12 +1,11 @@
import _ from 'lodash';
// Get a random property from an object
// returns random property (the value)
function trueRandom () {
return Math.random();
}
// Get a random property from an object
// returns random property (the value)
module.exports = function randomVal (obj, options = {}) {
let array = options.key ? _.keys(obj) : _.values(obj);
let random = (options.predictableRandom || trueRandom)();

View File

@@ -6,7 +6,7 @@ import splitWhitespace from '../libs/splitWhitespace';
import {
NotAuthorized,
} from '../libs/errors';
import randomVal from '../fns/randomVal';
import randomVal from '../libs/randomVal';
// TODO this is only used on the server
// move out of common?

View File

@@ -4,7 +4,7 @@ import _ from 'lodash';
import {
NotAuthorized,
} from '../libs/errors';
import randomVal from '../fns/randomVal';
import randomVal from '../libs/randomVal';
// TODO this is only used on the server
// move out of common?