/** * @license * Copyright Borda All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://borda.dev/license */ import { ActionCreatorWithPayload, ActionReducerMapBuilder, CaseReducer, Draft as ImmerDraft, EnhancedStore, PayloadActionCreator } from '@reduxjs/toolkit'; import { ReducerWithInitialState } from '@reduxjs/toolkit/dist/createReducer'; import type { StateDocument } from './Borda'; export interface Action { type: string; payload: T; } export type Draft = ImmerDraft; export type ReducerActions = Record void>; /** * Easily create redux reducers powered by immer.js * * @export * @template T * @param {T} init * @param {*} tree * @returns {fn} * @example * * import { createReducer } from '@borda/browser'; * * const person = createReducer<{ * firstName: string; * lastName: string; * }>( * // initial state * { * firstName: 'John', * lastName: 'Doe', * }, * // actions * { * setFirstName: (state, action) => { * state.firstName = action.payload; * }, * setLastName: (state, action) => { * state.lastName = action.payload; * }, * resetPerson: (state, action) => { * state.firstName = null; * state.lastName = null; * }, * } * ); */ export declare function createReducer(init: S, actions: ReducerActions): ReducerWithInitialState; /** * Easily create redux actions * * @export * @template T * @param {string} type * @returns {fn} * * @example * * import { createAction, dispatch } from '@borda/browser'; * * // create action * const increment = createAction('increment'); * * // dispatch * dispatch(increment(54)) */ export declare function createAction

(type: T): PayloadActionCreator; /** * Create custom redux store * @example * import { * createStore, * createReducer, * applyDevTools, * applyMiddleware * } from '@borda/browser'; * * export const counter = createReducer(0, { * increment: (state, action) => state + action.payload, * decrement: (state, action) => state - action.payload * }); * * // logger middleware example * const logger = store => next => action => { * console.log('dispatching', action); * const result = next(action); * console.log('next state', store.getState()); * return result; * }; * * createStore( * // list of reducers * { counter }, * // initial state * { counter: 420 }, * // composing enhancers * compose(applyDevTools({ production: false }), applyMiddleware(logger)) * ); * * store().subscribe(it => console.log(it, store().getState())); * * @export * @param {*} reducers * @param {*} preloadedState * @param {*} [enhancers] */ export declare function createStore({ name, reducers, preloadedState, inspect, traceLimit, }: { name: string; reducers: any; preloadedState: any; inspect?: boolean; traceLimit?: number; }): EnhancedStore; interface QueryPayload { key: string; value?: StateDocument; } type DocState = Record; /** * doc reducer + actions */ export declare const bordaSet: ActionCreatorWithPayload; export declare const bordaUnset: ActionCreatorWithPayload, string>; export declare const bordaReset: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"borda/reset">; export declare function borda(): ReducerWithInitialState; export type { ActionCreatorWithPayload, ActionReducerMapBuilder, CaseReducer, PayloadActionCreator, ReducerWithInitialState, };