Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return (state: object = defaultState, action: Action): any => {
if (state && action.type.substr(0, ACTION_PREFIX.length) === ACTION_PREFIX) {
const path = formatPath(action.meta ? action.meta.path : '');
const parts = path.split('.');
const newState = { ...state };
// make sure objects don't get mutated by cloning them
if (parts.length > 1) {
cloneObjects(newState, parts, 0);
}
return setValue(newState, path, action.payload);
}
return state;
};
};
if (XML_ATTRIBUTES.indexOf(key) !== -1) {
nv[key] = value
} else {
// detect expandable attrs for boolean values
// See https://vuejs.org/v2/guide/components-props.html#Passing-a-Boolean
if (
require('@nativescript/core/utils/types').isBoolean(nv[key]) &&
value === ''
) {
value = true
}
if (isAndroid && key.startsWith('android:')) {
set(nv, key.substr(8), value)
} else if (isIOS && key.startsWith('ios:')) {
set(nv, key.substr(4), value)
} else if (key.endsWith('.decode')) {
set(
nv,
key.slice(0, -7),
require('@nativescript/core/xml').XmlParser._dereferenceEntities(
value
)
)
} else {
set(nv, key, value)
}
}
} catch (e) {
// ignore
}
}
} else {
// detect expandable attrs for boolean values
// See https://vuejs.org/v2/guide/components-props.html#Passing-a-Boolean
if (
require('@nativescript/core/utils/types').isBoolean(nv[key]) &&
value === ''
) {
value = true
}
if (isAndroid && key.startsWith('android:')) {
set(nv, key.substr(8), value)
} else if (isIOS && key.startsWith('ios:')) {
set(nv, key.substr(4), value)
} else if (key.endsWith('.decode')) {
set(
nv,
key.slice(0, -7),
require('@nativescript/core/xml').XmlParser._dereferenceEntities(
value
)
)
} else {
set(nv, key, value)
}
}
} catch (e) {
// ignore
}
}
}
if (isAndroid && key.startsWith('android:')) {
set(nv, key.substr(8), value)
} else if (isIOS && key.startsWith('ios:')) {
set(nv, key.substr(4), value)
} else if (key.endsWith('.decode')) {
set(
nv,
key.slice(0, -7),
require('@nativescript/core/xml').XmlParser._dereferenceEntities(
value
)
)
} else {
set(nv, key, value)
}
}
} catch (e) {
// ignore
}
}
setData (data, callback) {
let next = clone(this.data)
for (let key in data) {
if (key.includes('[') || key.includes('.')) {
set(next, key, data[key])
} else {
next[key] = data[key]
}
}
this.data = next
if (typeof callback === 'function') {
callback()
}
}
export function setDefault(name, value) {
const previous = get(name);
log(`Defaulting "${name}" to ${JSON.stringify(value)}`);
deepSet(defaults, name, value);
addGlobalProxy(window, name);
if (previous === null || previous === undefined) {
event.emit('state-change', {name, value, previous});
}
}
export function set(name, value) {
const previous = get(name);
//log(`Setting "${name}" to ${JSON.stringify(value)}`);
deepSet(vars, name, value);
addGlobalProxy(window, name);
const now = get(name);
if (now !== previous) {
event.emit('state-change', {name, value: get(name), previous});
}
if (get('config.state.autosave')) {
saveToStorage();
}
}
.add('set-value', () => {
const obj = {
createUser: {
data: {
post: {
create: {},
},
},
},
}
setValue(obj, 'createUser.data.post.create.title', 'String')
})
.add('@strikeentco/set', () => {
Object.keys(bindings).forEach(prop => {
const getter = bindings[prop]
if (!getter) {
return
}
set(component._data, prop, getter(state))
})
}