UNPKG

wonder.js

Version:
68 lines (56 loc) 3.24 kB
'use strict'; var Log$WonderLog = require("wonder-log/lib/js/src/Log.js"); var Contract$WonderLog = require("wonder-log/lib/js/src/Contract.js"); var NullService$Wonderjs = require("../../atom/NullService.js"); var ArrayService$Wonderjs = require("../../atom/ArrayService.js"); var StateDataMain$Wonderjs = require("../../state/main/data/StateDataMain.js"); var IsDebugMainService$Wonderjs = require("../../state/main/state/IsDebugMainService.js"); var ArrayService$WonderCommonlib = require("wonder-commonlib/lib/js/src/ArrayService.js"); var MutableSparseMapService$WonderCommonlib = require("wonder-commonlib/lib/js/src/MutableSparseMapService.js"); var getComponent = MutableSparseMapService$WonderCommonlib.get; function unsafeGetComponent(uid, componentMap) { return Contract$WonderLog.ensureCheck((function (r) { return Contract$WonderLog.test(Log$WonderLog.buildAssertMessage("component exist", "not"), (function (param) { return Contract$WonderLog.assertNullableExist(r); })); }), IsDebugMainService$Wonderjs.getIsDebug(StateDataMain$Wonderjs.stateData), MutableSparseMapService$WonderCommonlib.unsafeGet(uid, componentMap)); } function hasComponent(uid, componentMap) { return NullService$Wonderjs.isInMap(MutableSparseMapService$WonderCommonlib.unsafeGet(uid, componentMap)); } function addComponent(uid, component, componentMap) { Contract$WonderLog.requireCheck((function (param) { return Contract$WonderLog.test(Log$WonderLog.buildAssertMessage("this type of the component shouldn\'t be added before", "not"), (function (param) { return Contract$WonderLog.assertFalse(hasComponent(uid, componentMap)); })); }), IsDebugMainService$Wonderjs.getIsDebug(StateDataMain$Wonderjs.stateData)); MutableSparseMapService$WonderCommonlib.set(uid, component, componentMap); return /* () */0; } var removeComponent = MutableSparseMapService$WonderCommonlib.deleteVal; var hasComponent$1 = hasComponent; function batchGetComponent(uidArray, componentMap) { return ArrayService$WonderCommonlib.reduceOneParam((function (arr, uid) { var match = MutableSparseMapService$WonderCommonlib.get(uid, componentMap); if (match !== undefined) { return ArrayService$Wonderjs.push(match, arr); } else { return arr; } }), /* array */[], uidArray); } function batchDisposeComponentWithUidMap(uidMap, componentRecord, handleFunc, componentArray) { return handleFunc(componentArray, uidMap, componentRecord); } function batchDisposeComponent(componentRecord, handleFunc, componentArray) { return handleFunc(componentArray, componentRecord); } exports.getComponent = getComponent; exports.unsafeGetComponent = unsafeGetComponent; exports.addComponent = addComponent; exports.removeComponent = removeComponent; exports.hasComponent = hasComponent$1; exports.batchGetComponent = batchGetComponent; exports.batchDisposeComponentWithUidMap = batchDisposeComponentWithUidMap; exports.batchDisposeComponent = batchDisposeComponent; /* Log-WonderLog Not a pure module */