UNPKG

@wordpress/hooks

Version:
8 lines (7 loc) 4.64 kB
{ "version": 3, "sources": ["../src/createHooks.ts"], "sourcesContent": ["/**\n * Internal dependencies\n */\nimport createAddHook from './createAddHook';\nimport createRemoveHook from './createRemoveHook';\nimport createHasHook from './createHasHook';\nimport createRunHook from './createRunHook';\nimport createCurrentHook from './createCurrentHook';\nimport createDoingHook from './createDoingHook';\nimport createDidHook from './createDidHook';\nimport type { Store } from './types';\n\n/**\n * Internal class for constructing hooks. Use `createHooks()` function\n *\n * Note, it is necessary to expose this class to make its type public.\n *\n * @private\n */\nexport class _Hooks {\n\tpublic actions: Store;\n\tpublic filters: Store;\n\n\tpublic addAction: ReturnType< typeof createAddHook >;\n\tpublic addFilter: ReturnType< typeof createAddHook >;\n\tpublic removeAction: ReturnType< typeof createRemoveHook >;\n\tpublic removeFilter: ReturnType< typeof createRemoveHook >;\n\tpublic hasAction: ReturnType< typeof createHasHook >;\n\tpublic hasFilter: ReturnType< typeof createHasHook >;\n\tpublic removeAllActions: ReturnType< typeof createRemoveHook >;\n\tpublic removeAllFilters: ReturnType< typeof createRemoveHook >;\n\tpublic doAction: ReturnType< typeof createRunHook >;\n\tpublic doActionAsync: ReturnType< typeof createRunHook >;\n\tpublic applyFilters: ReturnType< typeof createRunHook >;\n\tpublic applyFiltersAsync: ReturnType< typeof createRunHook >;\n\tpublic currentAction: ReturnType< typeof createCurrentHook >;\n\tpublic currentFilter: ReturnType< typeof createCurrentHook >;\n\tpublic doingAction: ReturnType< typeof createDoingHook >;\n\tpublic doingFilter: ReturnType< typeof createDoingHook >;\n\tpublic didAction: ReturnType< typeof createDidHook >;\n\tpublic didFilter: ReturnType< typeof createDidHook >;\n\n\tconstructor() {\n\t\tthis.actions = Object.create( null );\n\t\tthis.actions.__current = new Set();\n\n\t\tthis.filters = Object.create( null );\n\t\tthis.filters.__current = new Set();\n\n\t\tthis.addAction = createAddHook( this, 'actions' );\n\t\tthis.addFilter = createAddHook( this, 'filters' );\n\t\tthis.removeAction = createRemoveHook( this, 'actions' );\n\t\tthis.removeFilter = createRemoveHook( this, 'filters' );\n\t\tthis.hasAction = createHasHook( this, 'actions' );\n\t\tthis.hasFilter = createHasHook( this, 'filters' );\n\t\tthis.removeAllActions = createRemoveHook( this, 'actions', true );\n\t\tthis.removeAllFilters = createRemoveHook( this, 'filters', true );\n\t\tthis.doAction = createRunHook( this, 'actions', false, false );\n\t\tthis.doActionAsync = createRunHook( this, 'actions', false, true );\n\t\tthis.applyFilters = createRunHook( this, 'filters', true, false );\n\t\tthis.applyFiltersAsync = createRunHook( this, 'filters', true, true );\n\t\tthis.currentAction = createCurrentHook( this, 'actions' );\n\t\tthis.currentFilter = createCurrentHook( this, 'filters' );\n\t\tthis.doingAction = createDoingHook( this, 'actions' );\n\t\tthis.doingFilter = createDoingHook( this, 'filters' );\n\t\tthis.didAction = createDidHook( this, 'actions' );\n\t\tthis.didFilter = createDidHook( this, 'filters' );\n\t}\n}\n\nexport type Hooks = _Hooks;\n\n/**\n * Returns an instance of the hooks object.\n *\n * @return A Hooks instance.\n */\nfunction createHooks(): Hooks {\n\treturn new _Hooks();\n}\n\nexport default createHooks;\n"], "mappings": ";AAGA,OAAO,mBAAmB;AAC1B,OAAO,sBAAsB;AAC7B,OAAO,mBAAmB;AAC1B,OAAO,mBAAmB;AAC1B,OAAO,uBAAuB;AAC9B,OAAO,qBAAqB;AAC5B,OAAO,mBAAmB;AAUnB,IAAM,SAAN,MAAa;AAAA,EACZ;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEP,cAAc;AACb,SAAK,UAAU,uBAAO,OAAQ,IAAK;AACnC,SAAK,QAAQ,YAAY,oBAAI,IAAI;AAEjC,SAAK,UA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