diff options
author | kibigo! <marrus-sh@users.noreply.github.com> | 2017-07-13 03:26:08 -0700 |
---|---|---|
committer | kibigo! <marrus-sh@users.noreply.github.com> | 2017-07-13 03:26:08 -0700 |
commit | 35fda84ba830415a575b5f99f7405353ab8d3c93 (patch) | |
tree | 60f24d1b5c36605c8ed10c6c8b736c457cd1b9f9 /app/javascript/glitch/reducers/local_settings.js | |
parent | 5770d461b21cf5b6a8adcaa44d19832e11289960 (diff) |
Documentation pt. I
Diffstat (limited to 'app/javascript/glitch/reducers/local_settings.js')
-rw-r--r-- | app/javascript/glitch/reducers/local_settings.js | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/app/javascript/glitch/reducers/local_settings.js b/app/javascript/glitch/reducers/local_settings.js index db99f2c46..79ff96307 100644 --- a/app/javascript/glitch/reducers/local_settings.js +++ b/app/javascript/glitch/reducers/local_settings.js @@ -1,3 +1,32 @@ +/* + +`reducers/local_settings` +======================== + +> For more information on the contents of this file, please contact: +> +> - kibigo! [@kibi@glitch.social] + +This file provides our Redux reducers related to local settings. The +associated actions are: + + - __`STORE_HYDRATE` :__ + Used to hydrate the store with its initial values. + + - __`LOCAL_SETTING_CHANGE` :__ + Used to change the value of a local setting in the store. + +*/ + + /* * * * */ + +/* + +Imports +------- + +*/ + // Package imports // import Immutable from 'immutable'; @@ -7,6 +36,18 @@ import { STORE_HYDRATE } from '../../mastodon/actions/store'; // Our imports // import { LOCAL_SETTING_CHANGE } from '../actions/local_settings'; + /* * * * */ + +/* + +initialState +------------ + +You can see the default values for all of our local settings here. +These are only used if no previously-saved values exist. + +*/ + const initialState = Immutable.fromJS({ layout : 'auto', stretch : true, @@ -30,8 +71,46 @@ const initialState = Immutable.fromJS({ }, }); + /* * * * */ + +/* + +Helper functions +---------------- + +### `hydrate(state, localSettings)` + +`hydrate()` is used to hydrate the `local_settings` part of our store +with its initial values. The `state` will probably just be the +`initialState`, and the `localSettings` should be whatever we pulled +from `localStorage`. + +*/ + const hydrate = (state, localSettings) => state.mergeDeep(localSettings); + /* * * * */ + +/* + +`localSettings(state = initialState, action)` +--------------------------------------------- + +This function holds our actual reducer. + +If our action is `STORE_HYDRATE`, then we call `hydrate()` with the +`local_settings` property of the provided `action.state`. + +If our action is `LOCAL_SETTING_CHANGE`, then we set `action.key` in +our state to the provided `action.value`. Note that `action.key` MUST +be an array, since we use `setIn()`. + +> __Note :__ +> We call this function `localSettings`, but its associated object +> in the store is `local_settings`. + +*/ + export default function localSettings(state = initialState, action) { switch(action.type) { case STORE_HYDRATE: |