Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
commit(name, data) {
if (data && !isObject(data)) {
error(`[mutation]', 'The mutation data is not object type. name=${name} data=${data}`);
}
const context = {
getter: (name, data) => {
return this.getter.apply(this, [name, data]);
},
state: this._state
};
const fn = this._mutations[name];
if (!fn || typeof fn !== 'function') {
error(`[mutation]', 'The mutation is not a function. name=${name} data=${data}`);
}
debug('[mutation(before)]', name, this._state, data);
const triggers = fn.apply(null, [context, data]);
const validate = data => {
if (!isObject(data)) {
return 'レスポンスデータに誤りがあります。';
}
return null;
};
const trim = val => {
let loop;
if (isObject(val)) {
loop = forOwn;
} else if (isArray(val)) {
loop = forEach;
} else {
return;
}
loop(val, (v, k) => {
if (isNull(v)) {
val[k] = undefined;
}
if (isObject(v) || isArray(v)) {
trim(v);
}
});
};
trim(ret);
forOwn(newEndpoints, (endpoint, key) => {
if (!isObject(endpoint)) {
delete newEndpoints[key];
}
});
state.endpoints[version] = newEndpoints;
this.getPropertyValue = key => {
if (!isObject(this.opts.val)) {
return undefined;
}
return this.opts.val[key];
};
keys.forEach(key => {
const value = body[key];
if (isObject(value) || Array.isArray(value)) {
formData.append(key, JSON.stringify(value));
} else if (value != null) {
formData.append(key, value);
}
});
this.getVal = key => {
if (!isObject(this.opts.val)) {
return undefined;
}
return this.opts.val[key];
};
loop(val, (v, k) => {
if (isNull(v)) {
val[k] = undefined;
}
if (isObject(v) || isArray(v)) {
trim(v);
}
});
};