{
  "version": 3,
  "sources": ["../../src/store/actions.ts"],
  "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type {\n\tActionObject,\n\tStoreState,\n\tWPPreferencesPersistenceLayer,\n} from './types';\n\n/**\n * Returns an action object used in signalling that a preference should be\n * toggled.\n *\n * @param {string} scope The preference scope (e.g. core/edit-post).\n * @param {string} name  The preference name.\n */\nexport function toggle( scope: string, name: string ) {\n\t// @ts-expect-error We cannot properly type this until we have a fully-typed datastore\n\treturn function ( { select, dispatch } ) {\n\t\tconst currentValue = select.get( scope, name );\n\t\tdispatch.set( scope, name, ! currentValue );\n\t};\n}\n\ntype SetAction = ActionObject<\n\t'SET_PREFERENCE_VALUE',\n\t{ scope: string; name: string; value: any }\n>;\n\n/**\n * Returns an action object used in signalling that a preference should be set\n * to a value\n *\n * @param {string} scope The preference scope (e.g. core/edit-post).\n * @param {string} name  The preference name.\n * @param {*}      value The value to set.\n *\n * @return {SetAction} Action object.\n */\nexport function set( scope: string, name: string, value: any ): SetAction {\n\treturn {\n\t\ttype: 'SET_PREFERENCE_VALUE',\n\t\tscope,\n\t\tname,\n\t\tvalue,\n\t};\n}\n\ntype ScopedDefaults = StoreState[ 'defaults' ][ string ];\ntype SetDefaultsAction = ActionObject<\n\t'SET_PREFERENCE_DEFAULTS',\n\t{ scope: string; defaults: ScopedDefaults }\n>;\n\n/**\n * Returns an action object used in signalling that preference defaults should\n * be set.\n *\n * @param scope    The preference scope (e.g. core/edit-post).\n * @param defaults A key/value map of preference names to values.\n *\n * @return Action object.\n */\nexport function setDefaults(\n\tscope: string,\n\tdefaults: ScopedDefaults\n): SetDefaultsAction {\n\treturn {\n\t\ttype: 'SET_PREFERENCE_DEFAULTS',\n\t\tscope,\n\t\tdefaults,\n\t};\n}\n\ntype SetPersistenceLayerAction< D extends Object > = ActionObject<\n\t'SET_PERSISTENCE_LAYER',\n\t{\n\t\tpersistenceLayer: WPPreferencesPersistenceLayer< D >;\n\t\tpersistedData: D;\n\t}\n>;\n\n/**\n * Sets the persistence layer.\n *\n * When a persistence layer is set, the preferences store will:\n * - call `get` immediately and update the store state to the value returned.\n * - call `set` with all preferences whenever a preference changes value.\n *\n * `setPersistenceLayer` should ideally be dispatched at the start of an\n * application's lifecycle, before any other actions have been dispatched to\n * the preferences store.\n *\n * @param persistenceLayer The persistence layer.\n *\n * @return Action object.\n */\nexport async function setPersistenceLayer< D extends Object >(\n\tpersistenceLayer: WPPreferencesPersistenceLayer< D >\n): Promise< SetPersistenceLayerAction< D > > {\n\tconst persistedData = await persistenceLayer.get();\n\treturn {\n\t\ttype: 'SET_PERSISTENCE_LAYER',\n\t\tpersistenceLayer,\n\t\tpersistedData,\n\t};\n}\n\nexport type AvailableActions =\n\t| SetAction\n\t| SetDefaultsAction\n\t| SetPersistenceLayerAction< any >;\n"],
  "mappings": ";AAgBO,SAAS,OAAQ,OAAe,MAAe;AAErD,SAAO,SAAW,EAAE,QAAQ,SAAS,GAAI;AACxC,UAAM,eAAe,OAAO,IAAK,OAAO,IAAK;AAC7C,aAAS,IAAK,OAAO,MAAM,CAAE,YAAa;AAAA,EAC3C;AACD;AAiBO,SAAS,IAAK,OAAe,MAAc,OAAwB;AACzE,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAiBO,SAAS,YACf,OACA,UACoB;AACpB,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACD;AACD;AAyBA,eAAsB,oBACrB,kBAC4C;AAC5C,QAAM,gBAAgB,MAAM,iBAAiB,IAAI;AACjD,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACD;AACD;",
  "names": []
}
