@empathyco/x-components
Version:
Empathy X Components
115 lines • 6.03 kB
TypeScript
import type { MonadicFunction, NiladicFunction, SubObject } from '../utils/index';
import type { AnyWire, PayloadFactoryData, Wire, WireParams, WireService, WireServiceWithoutPayload } from './wiring.types';
/**
* Creates a wire that executes the function passed. This function will receive a
* {@link WireParams} object.
*
* @param fn - The function to execute whenever a new value is emitted to the observable.
* @returns The Wire function.
* @public
*/
export declare function createWireFromFunction<Payload>(fn: (parameters: WireParams<Payload>) => void): Wire<Payload>;
/**
* Creates a wire that commits a mutation to the store. This wire receives a function. This function
* is used to get the actual payload value passed to mutation.
* This wire can be used in every event, as it does not have a payload type associated.
*
* @param mutation - The full mutation path to commit. I.e. `x/searchBox/setQuery`.
* @param payloadFactory - A function that receives a {@link PayloadFactoryData | object}
* with the Store state, getters, payload and metadata as parameter.
* @returns A {@link AnyWire} wire that commits the mutation with the payload returned by the
* payloadFactory.
* @public
*/
export declare function wireCommit<Payload>(mutation: string, payloadFactory: (params: PayloadFactoryData<Payload>) => any): AnyWire;
/**
* Creates a wire that commits a mutation to the store. This wire can receive any value as payload.
* This wire can be used in every event, as it does not have a payload type associated.
*
* @param mutation - The full mutation path to commit. I.e. `x/searchBox/setQuery`.
* @param staticPayload - A static payload to pass to the mutation.
* @returns {@link AnyWire} A wire that commits the mutation with the staticPayload payload.
* @public
*/
export declare function wireCommit(mutation: string, staticPayload: any): AnyWire;
/**
* Creates a wire that commits a mutation to the store. This wire will commit to the store the
* payload that it receives in the observable.
*
* @param mutation - The full mutation path to commit. I.e. `x/searchBox/setQuery`.
* @typeParam Payload - The type of the payload that this wire will receive
* @returns {@link Wire} A wire that commits the mutation with the payload that it receives
* in the observable.
* @public
*/
export declare function wireCommit<Payload>(mutation: string): Wire<Payload>;
/**
* Creates a wire that commits a mutation to the store, but without any payload. This wire can
* be used in every event, as it does not have a payload type associated.
*
* @param mutation - The full mutation path to commit. I.e. `x/searchBox/setQuery`.
* @returns {@link AnyWire} A wire that commits the mutation without any payload.
* @public
*/
export declare function wireCommitWithoutPayload(mutation: string): AnyWire;
/**
* Creates a wire that dispatch an action to the store. This wire receives a function. This function
* is used to get the actual payload value passed to action.
* This wire can be used in every event, as it does not have a payload type associated.
*
* @param action - The full action path to dispatch. I.e. `x/querySuggestions/fetchSuggestions`.
* @param payloadFactory - A function that receives a {@link PayloadFactoryData | object}
* with the Store state, getters, payload and metadata as parameter.
* @returns A {@link AnyWire} wire that dispatches the action with the payload returned by the
* payloadFactory.
* @public
*/
export declare function wireDispatch<Payload>(action: string, payloadFactory: (params: PayloadFactoryData<Payload>) => any): AnyWire;
/**
* Creates a wire that dispatches an action to the store. This wire can be used in every event,
* as it does not have a payload type associated.
*
* @param action - The full action path to dispatch. I.e. `x/querySuggestions/fetchSuggestions`.
* @param staticPayload - A static payload to pass to the action which will be dispatched.
* @returns {@link AnyWire} A wire that dispatches the action with the staticPayload payload.
* @public
*/
export declare function wireDispatch(action: string, staticPayload: any): AnyWire;
/**
* Creates a wire that dispatches an action to the store. This wire will pass the payload
* received in the observable to the action.
*
* @param action - The full action path to dispatch. I.e. `x/querySuggestions/fetchSuggestions`.
* @typeParam Payload - The type of the payload that this wire will receive
* @returns {@link Wire} A wire that dispatches the action with the payload that it receives
* in the observable.
* @public
*/
export declare function wireDispatch<Payload>(action: string): Wire<Payload>;
/**
* Creates a wire that dispatches an action to the store, but without any payload. This wire can
* be used in every event, as it does not have a payload type associated.
*
* @param action - The full action path to dispatch. I.e. `x/querySuggestions/fetchSuggestions`.
* @returns {@link AnyWire} A wire that dispatches the action without any payload.
* @public
*/
export declare function wireDispatchWithoutPayload(action: string): AnyWire;
/**
* Creates a wires factory that can create wires that will invoke the service methods.
*
* @param service - The service to invoke its methods.
* @returns A factory to create wires that invoke the service methods.
* @public
*/
export declare function wireService<SomeService>(service: SomeService & SubObject<SomeService, MonadicFunction>): WireService<SubObject<SomeService, MonadicFunction>>;
/**
* Creates a wires factory that can create wires that will invoke the service methods but
* without payload.
*
* @param service - The service to invoke its methods.
* @returns A factory to create wires that invoke the service methods without payload.
* @public
*/
export declare function wireServiceWithoutPayload<SomeService>(service: SomeService & SubObject<SomeService, NiladicFunction>): WireServiceWithoutPayload<SubObject<SomeService, NiladicFunction>>;
//# sourceMappingURL=wires.factory.d.ts.map