I'm trying to works with ngrx store and faced with problem, to properly push data in my store and select it.
My store object look like
AppStore = {
chat: {
messages: []
}
}
and my reducers looks like
const initialState = {
messages: []
};
export const ChatReduce = (state = initialState, action:Action) => {
if (typeof state === 'undefined') {
return initialState;
}
switch(action.type){
case 'ADD_MESSAGE':
return {
...state,
messages: [...state.messages, action.payload]
};
default:
return state;
}
};
in case "ADD_MESSSAGE" I want to push new message object from action payload and return new state. what am I doing wrong? Right now my state's chat message array just rewrites one value every time I push new message, but old messages are not saves.
And after write to store, how to select messages of me state? Is it necessary to subscribe to data? I tried this.store.select('chat')
but how to get messages?