Remapping store
This commit is contained in:
@ -50,13 +50,6 @@ export function getServer(){
|
||||
}
|
||||
}
|
||||
|
||||
export function serverLoaded(server){
|
||||
return {
|
||||
type: 'SNAPCAST_SERVER_LOADED',
|
||||
server: server
|
||||
}
|
||||
}
|
||||
|
||||
export function setClientName(id, name){
|
||||
return {
|
||||
type: 'SNAPCAST_SET_CLIENT_NAME',
|
||||
@ -129,3 +122,51 @@ export function setGroupVolume(id, percent, old_percent = 0){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Record loaders
|
||||
*
|
||||
* We've got a loaded record, now we just need to plug it in to our state and stores.
|
||||
**/
|
||||
|
||||
export function serverLoaded(server){
|
||||
return serversLoaded([server]);
|
||||
}
|
||||
export function serversLoaded(servers){
|
||||
return {
|
||||
type: 'SNAPCAST_SERVERS_LOADED',
|
||||
servers: servers
|
||||
}
|
||||
}
|
||||
|
||||
export function clientLoaded(client){
|
||||
return clientsLoaded([client]);
|
||||
}
|
||||
export function clientsLoaded(clients){
|
||||
return {
|
||||
type: 'SNAPCAST_CLIENTS_LOADED',
|
||||
clients: clients
|
||||
}
|
||||
}
|
||||
|
||||
export function groupLoaded(group){
|
||||
return groupsLoaded([group]);
|
||||
}
|
||||
export function groupsLoaded(groups){
|
||||
return {
|
||||
type: 'SNAPCAST_SERVERS_LOADED',
|
||||
servers: group
|
||||
}
|
||||
}
|
||||
|
||||
export function streamLoaded(stream){
|
||||
return streamsLoaded([stream]);
|
||||
}
|
||||
export function streamsLoaded(streams){
|
||||
return {
|
||||
type: 'SNAPCAST_STREAMS_LOADED',
|
||||
streams: streams
|
||||
}
|
||||
}
|
||||
@ -2,31 +2,27 @@
|
||||
export default function reducer(snapcast = {}, action){
|
||||
switch (action.type){
|
||||
|
||||
case 'SNAPCAST_SERVER_LOADED':
|
||||
return Object.assign({}, snapcast, {
|
||||
streams: action.streams,
|
||||
groups: action.groups,
|
||||
clients: action.clients
|
||||
});
|
||||
case 'SNAPCAST_CLIENTS_LOADED':
|
||||
var clients = Object.assign({}, snapcast.clients);
|
||||
for (var client of action.clients){
|
||||
clients[client.uri] = client;
|
||||
}
|
||||
return Object.assign({}, snapcast, { clients: clients });
|
||||
|
||||
case 'SNAPCAST_GROUP_UPDATED':
|
||||
case 'SNAPCAST_SOURCES_LOADED':
|
||||
var sources = Object.assign({}, snapcast.sources);
|
||||
for (var source of action.sources){
|
||||
sources[source.uri] = source;
|
||||
}
|
||||
return Object.assign({}, snapcast, { sources: sources });
|
||||
|
||||
case 'SNAPCAST_GROUPS_LOADED':
|
||||
var groups = Object.assign({}, snapcast.groups);
|
||||
var group = groups[action.key];
|
||||
groups[action.key] = Object.assign({}, group, action.group);
|
||||
for (var group of action.groups){
|
||||
groups[group.uri] = group;
|
||||
}
|
||||
return Object.assign({}, snapcast, { groups: groups });
|
||||
|
||||
case 'SNAPCAST_CLIENT_UPDATED':
|
||||
var clients = Object.assign({}, snapcast.clients);
|
||||
var client = clients[action.key];
|
||||
client.config = Object.assign({}, client.config, action.client.config);
|
||||
clients[action.key] = client;
|
||||
return Object.assign({}, snapcast, { clients: clients });
|
||||
|
||||
case 'SNAPCAST_CLIENT_REMOVED':
|
||||
var clients = Object.assign({}, snapcast.clients);
|
||||
delete clients[action.key];
|
||||
return Object.assign({}, snapcast, { clients: clients });
|
||||
|
||||
default:
|
||||
return snapcast
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user