代码拉取完成,页面将自动刷新
import path from 'path'
import settings from 'electron-settings'
import sample from 'lodash/sample'
import isEqual from 'lodash/isEqual'
import camelCase from 'lodash/camelCase'
export default ({ key, hypotheses }) => {
const keyPath = camelCase(path.basename(key))
// Where in settings the test will be saved
const testPath = `splitTest.${keyPath}`
// Check if we've already saved this test
const savedTest = settings.get(testPath)
// If we've saved the test, using the same hypotheses...
if (savedTest && isEqual(savedTest.hypotheses, hypotheses)) {
// Return the value that was saved, ensuring that
// each user will always see the same result.
return savedTest.hypothesis
} else {
// Pick a random hypothesis
const hypothesis = chooseHypothesis({ key, hypotheses })
// Save random value for this test in settings
settings.set(testPath, { hypotheses, hypothesis })
// Return the random hypothesis
return hypothesis
}
}
// Guarantees that all exported hypotheses contain
// a valid `name` and `value` property.
function chooseHypothesis({ key, hypotheses }) {
const hypothesis = {}
const hypothesesIsArray = Array.isArray(hypotheses)
hypothesis.name = sample(
hypothesesIsArray ? hypotheses : Object.keys(hypotheses)
)
if (hypothesesIsArray) {
hypothesis.value = hypothesis.name
} else {
hypothesis.value = hypotheses[hypothesis.name]
}
return hypothesis
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。