UNPKG

@aller/blink

Version:

A library for tracking user behaviour.

58 lines (55 loc) 1.41 kB
import { ARTICLE_PREVIEW_SCREEN_ENTER, PAGE_INIT, CLICK } from '../actions'; export function singleArticlePreview(state = [], action: any) { switch (action.type) { case ARTICLE_PREVIEW_SCREEN_ENTER: { return { ...state, id: action.payload.id, context: action.payload.context, url: action.payload.url, title: action.payload.title, height: action.payload.height, width: action.payload.width, personalizationParametersRequested: action.payload.personalizationParametersRequested, personalizationSystemUsed: action.payload.personalizationSystemUsed, position: action.payload.position, }; } case CLICK: { return { ...state, id: action.payload.id, url: action.payload.url, clicked: true, }; } default: break; } return state; } export default function articlePreview( state: { [key: string]: any } = {}, action: any, ) { switch (action.type) { case PAGE_INIT: return {}; // Flush the store on pageLoad case ARTICLE_PREVIEW_SCREEN_ENTER: case CLICK: if (!action.payload.id) { return state; } return { ...state, [action.payload.id]: singleArticlePreview( state[action.payload.id], action, ), }; default: break; } return state; }