Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'redux-immutablejs' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
const fetchListSuccess = createAction(FETCH_LIST_SUCCESS);
const fetchListFailed = createAction(FETCH_LIST_FAILED);
export const updateListOrder = createAction(UPDATE_LIST_ORDER);
export const updateLastRead = createAction(UPDATE_LAST_READ);
// export const updateNovelStar = createAction(UPDATE_NOVEL_STAR);
const initialState = Immutable.fromJS({
fetching:true,
error:'',
directory:[],
directoryUrl:'',
order:'asc',
lastReadIndex:0,
});
export default createReducer(initialState,{
[FETCH_LIST](state,action) {
return state.merge({
directoryUrl:action.payload,
fetching:true,
error:'',
directory:[],
order:'asc',
lastReadIndex:0,
});
},
[FETCH_LIST_SUCCESS](state,action) {
if (action.payload.length>0
&& action.payload.length == state.get('directory').size
&& action.payload[action.payload.length-1].title == state.getIn(['directory',state.get('directory').size-1,'title'])
) {
return state.merge({
import { ActionConst } from 'react-native-router-flux';
import { createReducer } from 'redux-immutablejs'
import Immutable from 'immutable'
const initialState = Immutable.fromJS({
scene: {},
});
export default createReducer(initialState,{
[ActionConst.FOCUS](state,{scene}) {
return state.merge({
scene,
});
},
});
import Immutable from 'immutable';
import { createReducer } from 'redux-immutablejs';
import * as A from '../actions/demo-ui';
const initialState = Immutable.fromJS({
theme: 'materialUi',
endpoint: 'default'
});
export default createReducer(initialState, {
[A.UPDATE_DEMO_THEME]: (state, { theme }) => state.merge({ theme }),
[A.UPDATE_DEMO_ENDPOINT]: (state, { endpoint }) => state.merge({ endpoint })
});
*/
import { actionTypes } from '../actions/actions';
import { repeatVar } from '../utils';
import Immutable from 'immutable';
import { createReducer } from 'redux-immutablejs'
import { combineReducersStable } from '../redux-utils';
import { buildCreateMessage } from '../won-message-utils';
import won from '../won-es6';
const initialState = Immutable.fromJS({
isFetching: false,
didInvalidate: false,
matches: {}
})
export default createReducer(
initialState,
{
[actionTypes.matches.add]:(state,action)=>{
return state.setIn(['matches',action.payload.connection.uri],action.payload)
}
}
)
import { actionTypes } from '../actions/actions';
import { repeatVar } from '../utils';
import Immutable from 'immutable';
import { createReducer } from 'redux-immutablejs'
import { combineReducersStable } from '../redux-utils';
import { buildCreateMessage } from '../won-message-utils';
import won from '../won-es6';
const initialState = Immutable.fromJS({
isFetching: false,
didInvalidate: false,
incomingRequestsByNeed: {}
})
export default createReducer(
initialState,
{
[actionTypes.requests.incomingReceived]:(state,action)=>{
let byNeed = state.getIn(['incomingRequestsByNeed',action.payload.ownNeed['@id']])
if(!byNeed){
state.setIn(['incomingRequestsByNeed',action.payload.ownNeed['@id']],[action.payload])
}else{
}
let match = {"ownNeedData":action.payload.ownNeed,"connections":action.payload.connections}
return state.setIn(['matches',action.payload.connection.uri],action.payload)
},
[actionTypes.matches.add]:(state,action)=>{
return state.setIn(['matches',action.payload.connection.uri],action.payload)
import { GET_SNSLOGINS_SUCCESS,GET_SNSLOGINS_FAILURE} from 'actions/types'
import { createReducer } from 'redux-immutablejs'
import {fromJS} from 'immutable'
export default createReducer(fromJS({
logins:[]
}), {
[GET_SNSLOGINS_FAILURE]: (state, action) => state.set('logins',[]),
[GET_SNSLOGINS_SUCCESS]: (state,{json}) => state.set('logins',json.data)
})
[ARTICLE_LIST_FAILURE]: (state,action)=>state.set('isFetching',false)
})
export const articleDetail = createReducer(fromJS({}),{
[ARTICLE_DETAIL_SUCCESS]:(state,action)=>state.merge(action.articleDetail),
[ARTICLE_DETAIL_FAILURE]:(state,action)=>state,
[TOGGLE_LIKE_SUCCESS]:(state,action)=>{
return state.merge({
isLike:action.isLike,
like_count:action.like_count
})
},
[TOGGLE_LIKE_FAILURE]:(state,action)=>state
})
export const prenextArticle = createReducer(fromJS({
'next':{},'prev':{}
}),{
[PRENEXT_ARTICLE_SUCCESS]:(state,{json})=>{
return state.merge(json.data)
},
[PRENEXT_ARTICLE_FAILURE]:(state,{json})=>state
})
import {
CHANGE_STYLE_MODE,
GET_INDEX_IMG_SUCCESS,
GET_INDEX_IMG_FAILURE,
GET_CAPTCHAURL
} from 'actions/types'
import { createReducer } from 'redux-immutablejs'
import { fromJS } from 'immutable'
import img from 'assets/images/shanghai.jpg'
import { API_ROOT } from '../config'
import { getCookie,saveCookie } from 'utils/authService'
export default createReducer(fromJS({
indexImg:'',
styleMode: getCookie('styleMode') || 'day-mode',
captchaUrl: API_ROOT + 'users/getCaptcha?'
}), {
[CHANGE_STYLE_MODE]: (state, action) => {
let styleMode = state.get('styleMode') === 'day-mode'?'night-mode':'day-mode'
saveCookie('styleMode', styleMode)
return state.set('styleMode',styleMode)
},
[GET_CAPTCHAURL]: (state, action) => state.set('captchaUrl',action.captchaUrl),
[GET_INDEX_IMG_SUCCESS]: (state, {json}) => state.set('indexImg',json.img),
[GET_INDEX_IMG_FAILURE]: (state, {json}) => state.set('indexImg',img)
})
items: []
})
export const articleList = createReducer(initialState,{
[ARTICLE_LIST_REQUEST]: (state,action)=>state.set('isFetching',true),
[ARTICLE_LIST_SUCCESS]: (state,action)=>{
return state.merge({
isFetching:false,
isMore: !(action.json.data.length < action.itemsPerPage),
items: action.isAdd?state.get('items').concat(action.json.data):action.json.data
})
},
[ARTICLE_LIST_FAILURE]: (state,action)=>state.set('isFetching',false)
})
export const articleDetail = createReducer(fromJS({}),{
[ARTICLE_DETAIL_SUCCESS]:(state,action)=>state.merge(action.articleDetail),
[ARTICLE_DETAIL_FAILURE]:(state,action)=>state,
[TOGGLE_LIKE_SUCCESS]:(state,action)=>{
return state.merge({
isLike:action.isLike,
like_count:action.like_count
})
},
[TOGGLE_LIKE_FAILURE]:(state,action)=>state
})
export const prenextArticle = createReducer(fromJS({
'next':{},'prev':{}
}),{
[PRENEXT_ARTICLE_SUCCESS]:(state,{json})=>{
return state.merge(json.data)
import Immutable from "immutable";
import { createReducer } from "redux-immutablejs";
import * as A from "../actions/email-sign-in";
import { SET_ENDPOINT_KEYS } from "../actions/configure";
const initialState = {
loading: false,
errors: null,
form: {}
};
export default createReducer(Immutable.fromJS({}), {
[SET_ENDPOINT_KEYS]: (state, {endpoints}) => state.merge(endpoints.reduce((coll, k) => {
coll[k] = Immutable.fromJS(initialState);
return coll;
}, {})),
[A.EMAIL_SIGN_IN_START]: (state, {endpoint}) => state.setIn([endpoint, "loading"], true),
[A.EMAIL_SIGN_IN_COMPLETE]: (state, {endpoint}) => state.merge({[endpoint]: initialState}),
[A.EMAIL_SIGN_IN_ERROR]: (state, {endpoint, errors}) => state.mergeDeep({
[endpoint]: {
loading: false,
errors
}
}),