-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a32c7b
commit b04833a
Showing
9 changed files
with
193 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 file contains 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 file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//Add action for subscribing the stream | ||
export const AddStream = (stream) => { | ||
return { | ||
type: "ADD_STREAM", | ||
id: stream.id, | ||
}; | ||
}; | ||
|
||
// Add action for unsubscribing the stream | ||
export const DelStream = (stream) => { | ||
return { | ||
type: "DEL_STREAM", | ||
id: stream.id, | ||
}; | ||
}; | ||
|
||
// Add action for changing the id of the active stream | ||
export const ActiveStream = (stream) => { | ||
return { | ||
type: "ACTIVE_STREAM", | ||
id: stream.id, | ||
}; | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Imports all the required actions | ||
import { AddStream, DelStream, ActiveStream } from "../actions"; | ||
|
||
// initial state defined for the reducers and selectors | ||
export const initialState = { | ||
userProfile: { | ||
name: null, | ||
}, | ||
streams: [], | ||
activeStreamId: {}, | ||
}; | ||
|
||
// defining the reducer for the actions imported | ||
export const handleAction = (state = initialState, action) => { | ||
const { userProfile, streams, activeStreamId } = state; | ||
switch (action.type) { | ||
case "ADD_STREAM": { | ||
const new_stream; | ||
for (let i = 0; i < streams.length; i++) { | ||
if (streams[i].id === action.id) { | ||
new_stream = streams[i]; | ||
break; | ||
} | ||
} | ||
let updated_streams = streams; | ||
updated_streams.push(new_stream); | ||
const updated_state = { userProfile, updated_streams, activeStreamId }; | ||
return updated_state; | ||
} | ||
|
||
case "DEL_STREAM": { | ||
const updated_streams = streams.filter((stream) => stream.id !== action.id); | ||
const updated_state = { userProfile, updated_streams, activeStreamId }; | ||
return updated_state; | ||
} | ||
|
||
|
||
case "ACTIVE_STREAM": { | ||
const updated_activeStreamId = action.id; | ||
const updated_state = { userProfile, streams, updated_activeStreamId }; | ||
return updated_state; | ||
} | ||
|
||
default: | ||
return state; | ||
} | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { createSelector } from "reselect"; | ||
import { handleAction, initialState } from "../reducers"; | ||
|
||
// defining selector for list of the subscribed streams | ||
export const subscribedStreams = createSelector( | ||
(state = initialState) => state.streams | ||
); | ||
|
||
// defining selector for returning the active stream | ||
export const activeStream = createSelector( | ||
(state = initialState) => { | ||
for (let i = 0; i < state.streams.length; i++){ | ||
if (state.streams[i].id === state.activeStreamId) { | ||
return state.streams[i]; | ||
} | ||
} | ||
} | ||
); | ||
|
||
// defining selector for returning the user profile details | ||
export const userProfile = createSelector( | ||
(state = initialState) => state.userProfile | ||
); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { createStore } from "redux"; | ||
import { handleAction } from "../reducers"; | ||
|
||
const store = createStore( | ||
handleAction, | ||
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() | ||
); | ||
|
||
export default store; |
This file contains 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