Repository URL to install this package:
|
Version:
1.2.8 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createAction = createAction;
exports.getName = getName;
exports.setValue = exports.silently = void 0;
var _mobx = require("xmobx/mobx");
// const {getDebugName} = extras
const getPayload = change => {
const added = change.added,
addedCount = change.addedCount,
index = change.index,
removed = change.removed,
removedCount = change.removedCount;
return {
index,
added: added && (0, _mobx.toJS)(added),
addedCount,
removed: removed && (0, _mobx.toJS)(removed),
removedCount
};
};
function createAction(name, change) {
if (!change) {
// is action
return {
type: name
};
}
let action;
if (typeof change.newValue !== 'undefined') {
const key = typeof change.index !== 'undefined' ? change.index : change.name;
action = {
[key]: (0, _mobx.toJS)(change.newValue)
};
} else {
action = getPayload(change);
}
action.type = `┃ ${name}`;
return action;
}
function getName(obj) {
if (!obj || !(0, _mobx.isObservable)(obj)) {
return '';
}
let r = (0, _mobx.getDebugName)(obj);
let end = r.indexOf('.');
if (end === -1) {
end = undefined;
}
return r.substr(0, end);
}
/* eslint-disable no-param-reassign */
const silently = (fn, store) => {
store.__isRemotedevAction = true;
fn();
delete store.__isRemotedevAction;
};
exports.silently = silently;
function setValueAction(store, state) {
silently(() => {
if (store.importState) {
store.importState(state);
} else {
Object.keys(state).forEach(key => {
store[key] = state[key];
});
}
}, store);
return state;
}
setValueAction.__isRemotedevAction = true;
const setValue = (0, _mobx.action)('@@remotedev', setValueAction);
/* eslint-enable */
exports.setValue = setValue;