@empathyco/x-components
Version:
Empathy X Components
97 lines (94 loc) • 2.95 kB
JavaScript
import { namespacedWireCommit } from '../../wiring/namespaced-wires.factory.js';
import { createWiring } from '../../wiring/wiring.utils.js';
const moduleName = 'scroll';
const wireCommit = namespacedWireCommit(moduleName);
/**
* Saves the scroll position of a container to the store.
*
* @public
*/
const setScrollPositionWire = wireCommit('setScrollComponentState', ({ metadata, eventPayload }) => ({
newState: { position: eventPayload },
id: metadata.id,
}));
/**
* Saves the scroll direction of a container to the store.
*
* @public
*/
const setScrollDirectionWire = wireCommit('setScrollComponentState', ({ metadata, eventPayload }) => ({
newState: { direction: eventPayload },
id: metadata.id,
}));
/**
* Saves a boolean indicating if the scroll has almost reached the end of a container to the store.
*
* @public
*/
const setScrollHasAlmostReachedEndWire = wireCommit('setScrollComponentState', ({ metadata, eventPayload }) => ({
newState: { hasAlmostReachedEnd: eventPayload },
id: metadata.id,
}));
/**
* Saves a boolean indicating if the scroll has reached the end of a container to the store.
*
* @public
*/
const setScrollHasReachedEndWire = wireCommit('setScrollComponentState', ({ metadata, eventPayload }) => ({
newState: { hasReachedEnd: eventPayload },
id: metadata.id,
}));
/**
* Saves a boolean indicating if the scroll has reached the start of a container to the store.
*
* @public
*/
const setScrollHasReachedStartWire = wireCommit('setScrollComponentState', ({ metadata, eventPayload }) => ({
newState: { hasReachedStart: eventPayload },
id: metadata.id,
}));
/**
* Saves the selector of the item that should be scrolled into the view.
*
* @public
*/
const setPendingScrollToWire = wireCommit('setPendingScrollTo', ({ eventPayload: { scroll } }) => scroll);
/**
* Resets the selector of the scroll that is pending to restore.
*
* @public
*/
const clearPendingScrollToWire = wireCommit('setPendingScrollTo', '');
/**
* Wiring configuration for the {@link ScrollXModule | scroll module}.
*
* @internal
*/
const scrollWiring = createWiring({
UserScrolled: {
setScrollPositionWire,
},
UserChangedScrollDirection: {
setScrollDirectionWire,
},
UserReachedScrollStart: {
setScrollHasReachedStartWire,
},
UserAlmostReachedScrollEnd: {
setScrollHasAlmostReachedEndWire,
},
UserReachedScrollEnd: {
setScrollHasReachedEndWire,
},
ParamsLoadedFromUrl: {
setPendingScrollToWire,
},
ScrollRestoreSucceeded: {
clearPendingScrollToWire,
},
ScrollRestoreFailed: {
clearPendingScrollToWire,
},
});
export { clearPendingScrollToWire, scrollWiring, setPendingScrollToWire, setScrollDirectionWire, setScrollHasAlmostReachedEndWire, setScrollHasReachedEndWire, setScrollHasReachedStartWire, setScrollPositionWire };
//# sourceMappingURL=wiring.js.map