@hecom/constantgroup
Advanced tools
Comparing version 1.2.4 to 1.2.5
{ | ||
"name": "@hecom/constantgroup", | ||
"version": "1.2.4", | ||
"version": "1.2.5", | ||
"description": "Constant Group Management", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -5,5 +5,11 @@ import * as Specials from 'specials'; | ||
const SUB_PATH = 'constantGroup'; | ||
const instance = Specials.getInstance(); | ||
const config = { | ||
readFile: null, | ||
writeFile: null, | ||
}; | ||
export default { | ||
init: _init, | ||
load: _load, | ||
@@ -16,2 +22,7 @@ loadIfInvalid: _loadIfInvalid, | ||
function _init({readFile, writeFile}) { | ||
config.readFile = readFile; | ||
config.writeFile = writeFile; | ||
} | ||
function _clear() { | ||
@@ -21,12 +32,33 @@ instance.clearStorage(); | ||
function _load(constantId) { | ||
return Network.post({groupName: constantId}, Foundation.URL.ConstantGroupList) | ||
.then((result) => { | ||
const data = _generateTree(result.data); | ||
_setNecessaryField(data); | ||
_set(constantId, data); | ||
return data; | ||
function _processResultData(constantId, resultData) { | ||
const data = _generateTree(resultData); | ||
_setNecessaryField(data); | ||
_set(constantId, data); | ||
return data; | ||
} | ||
function _requestConstantGroup(constantId) { | ||
const { writeFile } = config; | ||
return Network.post({groupName: constantId}, Foundation.URL.ConstantGroupList).then((result) => { | ||
return writeFile(constantId, result.data, SUB_PATH).then(() => { | ||
return _processResultData(constantId, result.data); | ||
}); | ||
}); | ||
} | ||
function _load(constantId) { | ||
const { readFile } = config; | ||
if (!readFile) { | ||
throw new Error('ConstantGroup is not init. Please call ConstantGroup.init first'); | ||
} | ||
return readFile(constantId, SUB_PATH).then((resultData) => { | ||
if (resultData) { | ||
_requestConstantGroup(constantId); | ||
return _processResultData(constantId, resultData); | ||
} else { | ||
return _requestConstantGroup(constantId); | ||
} | ||
}); | ||
} | ||
function _loadIfInvalid(constantId) { | ||
@@ -33,0 +65,0 @@ if (_isValid(constantId)) { |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
8188
122
8