{
  "version": 3,
  "sources": ["../../src/store/reducer.ts"],
  "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n/**\n * Internal dependencies\n */\nimport type { StoreState, WPPreferencesPersistenceLayer } from './types';\nimport type { AvailableActions } from './actions';\n\n/**\n * Reducer returning the defaults for user preferences.\n *\n * This is kept intentionally separate from the preferences\n * themselves so that defaults are not persisted.\n *\n * @param state  Current state.\n * @param action Dispatched action.\n *\n * @return Updated state.\n */\nexport function defaults(\n\tstate: StoreState[ 'defaults' ] = {},\n\taction: AvailableActions\n): StoreState[ 'defaults' ] {\n\tif ( action.type === 'SET_PREFERENCE_DEFAULTS' ) {\n\t\tconst { scope, defaults: values } = action;\n\t\treturn {\n\t\t\t...state,\n\t\t\t[ scope ]: {\n\t\t\t\t...state[ scope ],\n\t\t\t\t...values,\n\t\t\t},\n\t\t};\n\t}\n\n\treturn state;\n}\n\ntype PreferencesReducer = (\n\tstate: StoreState[ 'preferences' ],\n\taction: AvailableActions\n) => StoreState[ 'preferences' ];\n\n/**\n * Higher order reducer that does the following:\n * - Merges any data from the persistence layer into the state when the\n *   `SET_PERSISTENCE_LAYER` action is received.\n * - Passes any preferences changes to the persistence layer.\n *\n * @param reducer The preferences reducer.\n *\n * @return The enhanced reducer.\n */\nfunction withPersistenceLayer( reducer: PreferencesReducer ) {\n\tlet persistenceLayer: WPPreferencesPersistenceLayer< any >;\n\n\treturn ( state: StoreState[ 'preferences' ], action: AvailableActions ) => {\n\t\t// Set up the persistence layer, and return the persisted data\n\t\t// as the state.\n\t\tif ( action.type === 'SET_PERSISTENCE_LAYER' ) {\n\t\t\tconst { persistenceLayer: persistence, persistedData } = action;\n\t\t\tpersistenceLayer = persistence;\n\t\t\treturn persistedData;\n\t\t}\n\n\t\tconst nextState = reducer( state, action );\n\t\tif ( action.type === 'SET_PREFERENCE_VALUE' ) {\n\t\t\tpersistenceLayer?.set( nextState );\n\t\t}\n\n\t\treturn nextState;\n\t};\n}\n\n/**\n * Reducer returning the user preferences.\n *\n * @param {Object} state  Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport const preferences = withPersistenceLayer( ( state = {}, action ) => {\n\tif ( action.type === 'SET_PREFERENCE_VALUE' ) {\n\t\tconst { scope, name, value } = action;\n\t\treturn {\n\t\t\t...state,\n\t\t\t[ scope ]: {\n\t\t\t\t...state[ scope ],\n\t\t\t\t[ name ]: value,\n\t\t\t},\n\t\t};\n\t}\n\n\treturn state;\n} );\n\nexport default combineReducers( {\n\tdefaults,\n\tpreferences,\n} );\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAgC;AAkBzB,SAAS,SACf,QAAkC,CAAC,GACnC,QAC2B;AAC3B,MAAK,OAAO,SAAS,2BAA4B;AAChD,UAAM,EAAE,OAAO,UAAU,OAAO,IAAI;AACpC,WAAO;AAAA,MACN,GAAG;AAAA,MACH,CAAE,KAAM,GAAG;AAAA,QACV,GAAG,MAAO,KAAM;AAAA,QAChB,GAAG;AAAA,MACJ;AAAA,IACD;AAAA,EACD;AAEA,SAAO;AACR;AAiBA,SAAS,qBAAsB,SAA8B;AAC5D,MAAI;AAEJ,SAAO,CAAE,OAAoC,WAA8B;AAG1E,QAAK,OAAO,SAAS,yBAA0B;AAC9C,YAAM,EAAE,kBAAkB,aAAa,cAAc,IAAI;AACzD,yBAAmB;AACnB,aAAO;AAAA,IACR;AAEA,UAAM,YAAY,QAAS,OAAO,MAAO;AACzC,QAAK,OAAO,SAAS,wBAAyB;AAC7C,wBAAkB,IAAK,SAAU;AAAA,IAClC;AAEA,WAAO;AAAA,EACR;AACD;AAUO,IAAM,cAAc,qBAAsB,CAAE,QAAQ,CAAC,GAAG,WAAY;AAC1E,MAAK,OAAO,SAAS,wBAAyB;AAC7C,UAAM,EAAE,OAAO,MAAM,MAAM,IAAI;AAC/B,WAAO;AAAA,MACN,GAAG;AAAA,MACH,CAAE,KAAM,GAAG;AAAA,QACV,GAAG,MAAO,KAAM;AAAA,QAChB,CAAE,IAAK,GAAG;AAAA,MACX;AAAA,IACD;AAAA,EACD;AAEA,SAAO;AACR,CAAE;AAEF,IAAO,sBAAQ,6BAAiB;AAAA,EAC/B;AAAA,EACA;AACD,CAAE;",
  "names": []
}
