Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return packet;
}
}
function processPacket(aprsSituation: State, packet) {
packet=ensurePacketReceivedAtIsDate(packet);
aprsSituation.rawPackets.push(packet);
aprsSituation.lastServerTime=Math.max(aprsSituation.lastServerTime,
packet.receivedAt.getTime());
// I suspect that the deduplications and summaries might be best
// done as selectors.
//calculateSummaries(state);
}
const aprsSituationReducer = createReducer(
initialState,
on(AprsSituationActions.receivedPacket,
function(aprsSituation, { packet }):State {
console.log('receivedPacket');
let start=Date.now();
// Since state is immutable, we need to copy the list of packets.
let newSituation:State = {
...aprsSituation,
rawPackets: [],
deduplicatedPackets: [],
lastServerTime: 0
};
aprsSituation.rawPackets.map(packet => {
processPacket(newSituation, packet);
});
// store
import * as LayoutActions from '@gcv/gene/store/actions/layout.actions';
export const layoutFeatureKey = 'layout';
export interface State {
showLeftSlider: boolean;
leftSliderContent: string;
}
const initialState: State = {
showLeftSlider: false,
leftSliderContent: null,
};
export const reducer = createReducer(
initialState,
on(LayoutActions.CloseLeftSlider, (state) => {
return {
...state,
showLeftSlider: false,
};
}),
on(LayoutActions.OpenLeftSlider, (state) => {
return {
...state,
showLeftSlider: true,
};
}),
on(LayoutActions.ToggleLeftSlider, (state) => {
return {
...state,
// HACK: These imports are for type inference.
// https://github.com/bazelbuild/rules_nodejs/issues/1013
/** @typehack */ import * as _typeHackStore from '@ngrx/store/store';
const initialState: CoreState = {
activePlugin: null,
plugins: {},
pluginsListLoaded: {
state: DataLoadState.NOT_LOADED,
lastLoadedTimeInMs: null,
},
reloadPeriodInMs: 30000,
reloadEnabled: true,
};
const reducer = createReducer(
initialState,
on(
actions.changePlugin,
(state: CoreState, {plugin}): CoreState => {
return {...state, activePlugin: plugin};
}
),
on(
actions.pluginsListingRequested,
(state: CoreState): CoreState => {
return {
...state,
pluginsListLoaded: {
...state.pluginsListLoaded,
state: DataLoadState.LOADING,
},
it('should work with createReducer', () => {
const state = {
prop: 'value',
control: INITIAL_STATE.controls.inner,
group: INITIAL_STATE,
array: INITIAL_STATE.controls.inner5,
};
const reducer = createReducer(
state,
onNgrxForms(),
);
const wrappedReducer = wrapReducerWithFormStateUpdate(reducer, s => s.control, s => ({ ...s }));
let resultState = wrappedReducer(state, new MarkAsTouchedAction(FORM_CONTROL_INNER_ID));
expect(resultState.control).not.toBe(INITIAL_STATE.controls.inner);
resultState = wrappedReducer(state, new MarkAsTouchedAction(FORM_CONTROL_ID));
expect(resultState.group).not.toBe(INITIAL_STATE);
resultState = wrappedReducer(state, new MarkAsTouchedAction(FORM_CONTROL_INNER5_ID));
expect(resultState.array).not.toBe(INITIAL_STATE.controls.inner5);
});
});
import { createReducer, on, Action } from '@ngrx/store';
import * as layoutActions from 'app/core/store/actions';
export interface State {
showSidenav: boolean;
title: string;
}
const initialState: State = {
showSidenav: false,
title: 'Home',
};
const layoutReducer = createReducer(
initialState,
on(layoutActions.closeSidenav, (state) => ({
...state,
showSidenav: false,
})),
on(layoutActions.openSidenav, (state) => ({
...state,
showSidenav: true,
})),
on(layoutActions.toggleSidenav, (state) => ({
...state,
showSidenav: !state.showSidenav,
})),
on(layoutActions.setTitle, (state, { title }) => ({
...state,
title,
export const competitionFeatureKey = 'competition'
export interface State {
problems: Problem[]
solutions: Solution[]
teamID: string
}
export const initialState: State = {
problems: [],
solutions: [],
teamID: '',
}
const competitionReducer = createReducer(
initialState,
on(CompetitionActions.loadTeamSucceed, (state, { id }) => ({ ...state, teamID: id })),
on(CompetitionActions.problemAdded, (state, payload) => ({ ...state, problems: [...state.problems, payload] })),
on(CompetitionActions.problemModified, (state, payload) => ({
...state,
problems: state.problems.map(e => {
if (e.id !== payload.id) return e
return payload
}),
})),
on(CompetitionActions.problemRemoved, (state, payload) => ({
...state,
problems: state.problems.filter(e => e.id !== payload.id),
})),
favorited: false,
favoritesCount: 0,
author: {
username: '',
bio: '',
image: '',
following: false,
loading: false,
},
},
comments: [],
loaded: false,
loading: false,
};
const reducer = createReducer(
articleInitialState,
on(ArticleActions.loadArticleSuccess, (state, action) => ({
...state,
data: action.article,
loaded: true,
loading: false,
})),
on(ArticleActions.loadArticleFail, state => ({
...state,
data: articleInitialState.data,
loaded: false,
loading: false,
})),
on(ArticleActions.addCommentSuccess, (state, action) => {
const comments: ArticleComment[] = [action.comment, ...state.comments];
return { ...state, comments };
});
export const initialState: BookState = bookAdapter.getInitialState({
ids: ['123'],
entities: {
'123': {
id: '123',
title: 'Reactive Programming with Angular and ngrx',
author: 'Oren Farhi',
description:
'Learn to Harness the Power of Reactive Programming with RxJS and ngrx Extensions'
}
}
});
const reducer = createReducer(
initialState,
on(actionBooksUpsertOne, (state, { book }) =>
bookAdapter.upsertOne(book, state)
),
on(actionBooksDeleteOne, (state, { id }) => bookAdapter.removeOne(id, state))
);
export function bookReducer(state: BookState | undefined, action: Action) {
return reducer(state, action);
}
export const initialState: State = {
pending: false,
errorMessage: '',
textMessage: '',
booking: undefined,
token: undefined,
bookingResponse: {
name: '',
bookingDate: '',
bookingToken: '',
tableId: undefined,
email: '',
},
};
const bookTableReducer = createReducer(
initialState,
on(bookTableActions.bookTable, (state, { booking }) => ({
...state,
pending: true,
booking: booking,
})),
on(bookTableActions.bookTableSuccess, (state, { bookingResponse }) => ({
...state,
pending: false,
bookingResponse: bookingResponse,
})),
on(bookTableActions.bookTableFail, (state, { error }) => ({
...state,
pending: false,
errorMessage: error.message,
})),
import { createReducer, Action, on } from "@ngrx/store";
import { JobsState, initialJobsState } from "state-management/state/jobs.store";
import * as fromActions from "state-management/actions/jobs.actions";
const reducer = createReducer(
initialJobsState,
on(fromActions.fetchJobsAction, state => ({ ...state, isLoading: true })),
on(fromActions.fetchJobsCompleteAction, (state, { jobs }) => ({
...state,
jobs,
isLoading: false
})),
on(fromActions.fetchJobsFailedAction, state => ({
...state,
isLoading: false
})),
on(fromActions.fetchCountAction, state => ({ ...state, isLoading: true })),
on(fromActions.fetchCountCompleteAction, (state, { count }) => ({
...state,
isLoading: false,