patternplate-client
Version:
Universal javascript client application for patternplate
38 lines (31 loc) • 602 B
JavaScript
export default scrollDemo;
export const type = 'SCROLL_DEMO';
let loop;
let frame;
function scrollDemo(payload) {
return (dispatch, getState) => {
function run() {
loop = global.requestAnimationFrame(() => {
const state = getState();
if (state.scrollDemoX.x !== frame.x) {
dispatch({
type: 'SCROLL_DEMO_X',
payload: frame.x
});
}
if (state.scrollDemoY.y !== frame.y) {
dispatch({
type: 'SCROLL_DEMO_Y',
payload: frame.y
});
}
run();
});
}
if (!loop) {
run();
}
frame = payload;
};
}
scrollDemo.type = type;