This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case EMessageActions.AddMessage: | |
const channelId = action.payload[0]; | |
const newMsg = action.payload[1]; | |
const entity = state.entities[channelId]; | |
const newMsgArray = [ | |
...entity.messages, | |
newMsg | |
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addMessage(msg: string) { | |
this.messages = [ | |
...this.messages, | |
msg | |
]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.messages$ = store.pipe(select(selectCurrentChannelMessages)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gets the channel id of the currently selected channel | |
export const selectCurrentChannelId = createSelector( | |
selectMessagesState, | |
getSelectedChannelId | |
); | |
export const selectMessageEntities = createSelector( | |
selectMessagesState, | |
selectMessageContainerEntities | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const messageAdapter: EntityAdapter<MessageContainer> = createEntityAdapter<MessageContainer>({ | |
selectId: messageContainer => messageContainer.channelId | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
messages: Observable<string[]>; | |
constructor(public messageService: MessageService) { | |
this.messages = messageService.messages$; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// maintains messages across channels | |
private messageDB = {1: [], 2: [], 3: []}; | |
// Tracks messages for the currently selected channel | |
private messageSubject$ = new BehaviorSubject<string[]>([]); | |
public readonly messages$ = this.messageSubject$.asObservable(); | |
private selectedChannelId: number; | |
constructor() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Updatess the corresponding channel's name. Triggers change detection by returning a new array. | |
* @param channel channel with updated name | |
*/ | |
updateChannel(channel: Channel) { | |
this.channels = this.channels.map(c => c.id === channel.id ? {...c, name: channel.name} : {...c}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const selectChannelsState = createFeatureSelector<ChannelsState>('channels'); | |
export const selectChannelList = createSelector( | |
selectChannelsState, | |
(state: ChannelsState) => state.channels | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const defaultChannels: Channel[] = [ | |
{ name: "Rocket League", id: 1 }, | |
{ name: "Aficionados", id: 2 }, | |
{ name: "Work", id: 3 } | |
] | |
export interface ChannelsState { | |
channels: Channel[]; | |
selectedChannelId: ChannelId | null; | |
} |
NewerOlder