mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-25 02:57:30 +00:00
Stub out ability to serialize state
This commit is contained in:
parent
c98143aedc
commit
5b6603cce9
5 changed files with 43 additions and 5 deletions
|
|
@ -1,4 +1,10 @@
|
|||
import { CLOSE_WINAMP, STOP, TOGGLE_VISUALIZER_STYLE } from "../actionTypes";
|
||||
import {
|
||||
CLOSE_WINAMP,
|
||||
STOP,
|
||||
TOGGLE_VISUALIZER_STYLE,
|
||||
RESTORE_SERIALIZED_STATE
|
||||
} from "../actionTypes";
|
||||
import { SERIALIZATION_VERSION } from "../constants";
|
||||
|
||||
export {
|
||||
toggleDoubleSizeMode,
|
||||
|
|
@ -78,3 +84,17 @@ export function close() {
|
|||
export function toggleVisualizerStyle() {
|
||||
return { type: TOGGLE_VISUALIZER_STYLE };
|
||||
}
|
||||
|
||||
export function restoreSerializedState(serializedState) {
|
||||
if (serializedState.version !== SERIALIZATION_VERSION) {
|
||||
// When SERIALIZATION_VERSION changes, will need to provide mapper functions
|
||||
// to transform old versions to new versions here.
|
||||
//
|
||||
// Having types will make doing this translation much easier.
|
||||
//
|
||||
// For now we will throw as reminder of how important it is to remember to
|
||||
// do this translation.
|
||||
throw new Error("Invalid serializaiton version");
|
||||
}
|
||||
return { type: RESTORE_SERIALIZED_STATE, serializedState };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,3 +70,4 @@ export const DISABLE_MARQUEE = "DISABLE_MARQUEE";
|
|||
export const SET_DUMMY_VIZ_DATA = "SET_DUMMY_VIZ_DATA";
|
||||
export const SET_WINDOW_VISIBILITY = "SET_WINDOW_VISIBILITY";
|
||||
export const LOADING = "LOADING";
|
||||
export const RESTORE_SERIALIZED_STATE = "RESTORE_SERIALIZED_STATE";
|
||||
|
|
|
|||
|
|
@ -52,3 +52,5 @@ export const MEDIA_STATUS = {
|
|||
STOPPED: "STOPPED",
|
||||
PAUSED: "PAUSED"
|
||||
};
|
||||
|
||||
export const SERIALIZATION_VERSION = 1;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ import {
|
|||
TRACK_HEIGHT,
|
||||
WINDOW_RESIZE_SEGMENT_WIDTH,
|
||||
WINDOW_RESIZE_SEGMENT_HEIGHT,
|
||||
WINDOW_WIDTH
|
||||
WINDOW_WIDTH,
|
||||
SERIALIZATION_VERSION
|
||||
} from "./constants";
|
||||
import { createPlaylistURL } from "./playlistHtml";
|
||||
import * as fromPlaylist from "./reducers/playlist";
|
||||
|
|
@ -329,3 +330,9 @@ export const getSkinPlaylistStyle = state => {
|
|||
|
||||
export const getVisualizerStyle = state =>
|
||||
fromDisplay.getVisualizerStyle(state.display);
|
||||
|
||||
export const serialize = state => {
|
||||
return {
|
||||
version: SERIALIZATION_VERSION
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import getStore from "./store";
|
|||
import App from "./components/App";
|
||||
import Hotkeys from "./hotkeys";
|
||||
import Media from "./media";
|
||||
import { getTrackCount, getTracks } from "./selectors";
|
||||
import * as Selectors from "./selectors";
|
||||
import {
|
||||
setSkinFromUrl,
|
||||
loadMediaFiles,
|
||||
|
|
@ -173,7 +173,7 @@ class Winamp {
|
|||
|
||||
// Append this array of tracks to the end of the current playlist.
|
||||
appendTracks(tracks) {
|
||||
const nextIndex = getTrackCount(this.store.getState());
|
||||
const nextIndex = Selectors.getTrackCount(this.store.getState());
|
||||
this.store.dispatch(loadMediaFiles(tracks, LOAD_STYLE.BUFFER, nextIndex));
|
||||
}
|
||||
|
||||
|
|
@ -186,9 +186,17 @@ class Winamp {
|
|||
return this._actionEmitter.on(CLOSE_WINAMP, cb);
|
||||
}
|
||||
|
||||
serialize() {
|
||||
return Selectors.serialize(this.store.getState());
|
||||
}
|
||||
|
||||
restoreSerializedState(serializedState) {
|
||||
this.store.dispatch(this.restoreSerializedState(serializedState));
|
||||
}
|
||||
|
||||
onTrackDidChange(cb) {
|
||||
return this._actionEmitter.on(SET_MEDIA, action => {
|
||||
const tracks = getTracks(this.store.getState());
|
||||
const tracks = Selectors.getTracks(this.store.getState());
|
||||
const track = tracks[action.id];
|
||||
if (track == null) {
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue