function rewind (history, p) { if (!p) { return history } var i = findIndex(history, p) if (i === -1) { return undefined } return history.slice(i) }
modifyInstance(cache, instance) { const vipAddresses = this.splitVipAddress(instance.vipAddress); const appName = instance.app.toUpperCase(); vipAddresses.forEach((vipAddress) => { const index = findIndex(cache.vip[vipAddress], findInstance(instance)); if (index > -1) cache.vip[vipAddress].splice(index, 1, instance); else this.addInstance(cache, instance); }); const index = findIndex(cache.app[appName], findInstance(instance)); if (index > -1) cache.app[appName].splice(cache.vip[instance.vipAddress], 1, instance); else this.addInstance(cache, instance); }
// Set default state. defaultState () { const options = this.props.options const checkedIndex = findIndex(options, function (item) { return item.checked || item.defaultChecked }) const listName = this.props.listName || utils.unique() this.state = { checkedIndex: checkedIndex, listName: listName } }
componentWillReceiveProps(nextProps) { if (this.state.environmentIndex === -1 && nextProps.envParams) { this.setState({ environmentIndex: findIndex(nextProps.environments, ['name', nextProps.envParams]) }); } if (nextProps.envParams && nextProps.envParams !== this.props.envParams) { const environmentIndex = findIndex(nextProps.environments, ['name', nextProps.envParams]); this.setState({ environmentIndex }); } }
export function checkFormValidity(formData, formValidations) { const errors = []; forEach(formData, (value, key) => { const validationValue = formValidations[findIndex(formValidations, ['name', key])]; if (!isUndefined(validationValue)) { const inputErrors = validate(value, validationValue.validations); if (!isEmpty(inputErrors)) { errors.push({ name: key, errors: inputErrors }); } } }); return errors; }
state .set('showButtons', showButtons) .updateIn(['model', 'attributes'], (list) => list.splice(action.position, 1)) .updateIn(['model', 'attributes'], (list) => list.splice(findIndex(list.toJS(), ['name', attributeKey]), 1))
onSetGenre(data) { let index = findIndex(this.movies, function(m) { return m.id == data.movieId; }); if (index >= 0) { if (!this.movies[index].genres) { this.movies[index].genres = []; } this.movies[index].genres.push(data.genre); } }
updateInfo(name, value, id) { let tempApts = this.state.myAppointment; let aptIndex = findIndex(this.state.myAppointment, { aptId: id }); tempApts[aptIndex][name] = value; this.setState({ myAppointment: tempApts }); }
Object.keys(modifiedData).reduce((acc, key) => { if (isEmpty(get(modifiedData, key)) && !isBoolean(get(modifiedData, key))) { acc.push({ name: key, errors: [{ id: 'components.Input.error.validation.required' }] }); } if (!isEmpty(get(modifiedData, 'password')) && !isEmpty(get(modifiedData, 'confirmPassword')) && findIndex(acc, ['name', 'confirmPassword']) === -1) { if (modifiedData.password.length < 6) { acc.push({ name: 'password', errors: [{ id: 'users-permissions.components.Input.error.password.length' }] }); } if (get(modifiedData, 'password') !== get(modifiedData, 'confirmPassword')) { acc.push({ name: 'confirmPassword', errors: [{ id: 'users-permissions.components.Input.error.password.noMatch' }] }); } } return acc; }, [])
const mapStateToProps = (state) => { const editingUserIndex = findIndex(state.users, (user) => { return state.appDetails.editingUser === user.id }) return { initialValues: state.users[editingUserIndex] } }
componentDidMount() { const environmentIndex = this.props.envParams ? findIndex(this.props.environments, ['name', this.props.envParams]) : 0; this.setState({ environmentIndex }); }
deleteInstance(cache, instance) { const vipAddresses = this.splitVipAddress(instance.vipAddress); const appName = instance.app.toUpperCase(); vipAddresses.forEach((vipAddress) => { const index = findIndex(cache.vip[vipAddress], findInstance(instance)); if (index > -1) cache.vip[vipAddress].splice(index, 1); }); const index = findIndex(cache.app[appName], findInstance(instance)); if (index > -1) cache.app[appName].splice(cache.vip[instance.vipAddress], 1); }
onSetMovie(movie) { let index = findIndex(this.movies, function(m) { return m.id == movie.id; }); if (index >= 0) { this.movies[index] = movie; } }
const findChangeBlocks = changes => { const start = findIndex(changes, change => !change.isNormal); if (start === -1) { return []; } const end = findIndex(changes, change => change.isNormal, start); if (end === -1) { return [changes.slice(start)]; } return [ changes.slice(start, end), ...findChangeBlocks(changes.slice(end)) ]; }
export function checkFormValidity(formData, formValidations) { const errors = []; forEach(formData, (value, key) => { const validationValue = formValidations[findIndex(formValidations, ['name', key])]; if (!isUndefined(validationValue)) { const inputErrors = validate(value, validationValue.validations); if (!isEmpty(inputErrors)) { errors.push({ name: key, errors: inputErrors }); } } }); return errors; }