New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

kea

Package Overview
Dependencies
Maintainers
1
Versions
233
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kea - npm Package Compare versions

Comparing version 2.2.0-rc.5 to 2.2.0-rc.6

lib/playground/complexLogic.d.ts

16

lib/index.cjs.js

@@ -152,3 +152,3 @@ 'use strict';

}
} else {
} else if (typeof otherLogic === 'function') {
logic.selectors[to] = from === '*' ? otherLogic : function (state, props) {

@@ -170,5 +170,4 @@ var values = otherLogic(state, props);

if (mapping.length % 2 === 1) {
console.error("[KEA] uneven mapping given to connect:", mapping);
console.trace();
return null;
console.error(mapping);
throw new Error("[KEA] Uneven mapping given to connect");
}

@@ -182,2 +181,7 @@

if (!Array.isArray(array)) {
console.error(mapping);
throw new Error('[KEA] Invalid mapping given to connect. Make sure every second element is an array!');
}
for (var j = 0; j < array.length; j++) {

@@ -986,3 +990,3 @@ if (array[j].includes(' as ')) {

logic.events[key] = function () {
oldEvent();
oldEvent && oldEvent();
newEvent && newEvent();

@@ -1277,3 +1281,3 @@ };

return {
paths: undefined,
paths: [],
reducers: {},

@@ -1280,0 +1284,0 @@ preloadedState: undefined,

@@ -27,3 +27,3 @@ import { AnyAction, Reducer, Middleware, compose, StoreEnhancer, Store, Action } from 'redux';

pathString: string;
props: Props;
props: any;
propTypes: Record<string, any>;

@@ -38,7 +38,4 @@ reducers: Record<string, any>;

events: PartialRecord<LogicEventType, () => void>;
__keaTypeGenInternalSelectorTypes: Record<string, (...args: any) => any>;
__keaTypeGenInternalReducerActions: Record<string, (...args: any) => {
type: string;
payload: any;
}>;
__keaTypeGenInternalSelectorTypes: Record<string, any>;
__keaTypeGenInternalReducerActions: Record<string, any>;
}

@@ -81,6 +78,6 @@ interface BuiltLogicAdditions {

declare type ListenerDefinitionsForRecord<A extends Record<string, (...args: any) => any>> = {
[K in keyof A]?: (payload: ReturnType<A[K]>['payload'], breakpoint: BreakPointFunction, action: ReturnType<A[K]>, previousState: any) => void | Promise<void>;
[K in keyof A]?: ListenerFunction<ReturnType<A[K]>>;
};
declare type ListenerDefinitions<LogicType extends Logic> = ListenerDefinitionsForRecord<LogicType['actionCreators']> & ListenerDefinitionsForRecord<LogicType['__keaTypeGenInternalReducerActions']>;
declare type ListenerFunction = (payload: any, breakpoint: BreakPointFunction, action: any, previousState: any) => void | Promise<void>;
declare type ListenerFunction<A extends AnyAction = any> = (payload: A['payload'], breakpoint: BreakPointFunction, action: A, previousState: any) => void | Promise<void>;
declare type ListenerFunctionWrapper = (action: any, previousState: any) => void;

@@ -247,5 +244,6 @@ declare type SharedListenerDefinitions = Record<string, ListenerFunction>;

whitelist: false | Record<string, boolean>;
combined: ReducerFunction;
combined: ReducerFunction | undefined;
};
store: Store;
__store: Store | undefined;
options: InternalContextOptions;

@@ -257,3 +255,3 @@ }

declare function useKea(input: LogicInput, deps?: any[]): LogicWrapper;
declare function useKea(input: LogicInput, deps?: never[]): LogicWrapper;
declare function useValues<L extends BuiltLogic | LogicWrapper>(logic: L): L['values'];

@@ -260,0 +258,0 @@ declare function useAllValues<L extends BuiltLogic | LogicWrapper>(logic: L): L['values'];

@@ -148,3 +148,3 @@ import { createSelector } from 'reselect';

}
} else {
} else if (typeof otherLogic === 'function') {
logic.selectors[to] = from === '*' ? otherLogic : function (state, props) {

@@ -166,5 +166,4 @@ var values = otherLogic(state, props);

if (mapping.length % 2 === 1) {
console.error("[KEA] uneven mapping given to connect:", mapping);
console.trace();
return null;
console.error(mapping);
throw new Error("[KEA] Uneven mapping given to connect");
}

@@ -178,2 +177,7 @@

if (!Array.isArray(array)) {
console.error(mapping);
throw new Error('[KEA] Invalid mapping given to connect. Make sure every second element is an array!');
}
for (var j = 0; j < array.length; j++) {

@@ -982,3 +986,3 @@ if (array[j].includes(' as ')) {

logic.events[key] = function () {
oldEvent();
oldEvent && oldEvent();
newEvent && newEvent();

@@ -1273,3 +1277,3 @@ };

return {
paths: undefined,
paths: [],
reducers: {},

@@ -1276,0 +1280,0 @@ preloadedState: undefined,

@@ -49,2 +49,10 @@ import { Logic } from '../src/types';

key: undefined;
listeners: {
setUsername: ((action: {
type: 'set username (samples.githubLogic)';
payload: {
username: string;
};
}, previousState: any) => void | Promise<void>)[];
};
path: ['samples', 'githubLogic'];

@@ -79,2 +87,3 @@ pathString: 'samples.githubLogic';

};
sharedListeners: {};
values: {

@@ -81,0 +90,0 @@ username: string;

@@ -1,3 +0,6 @@

import { Logic, LogicInput } from '../../types';
import { BuiltLogic, Logic, LogicInput, LogicWrapper, Selector } from '../../types';
export declare function createConnect(logic: Logic, input: LogicInput): void;
export declare function deconstructMapping(mapping: any): any[];
declare type LogicMapping = (Logic | BuiltLogic | LogicWrapper | Selector | Record<string, any> | string[])[];
declare type DeconstructedLogicMapping = [Logic | BuiltLogic | LogicWrapper | Selector | Record<string, any>, string, string][];
export declare function deconstructMapping(mapping: LogicMapping): DeconstructedLogicMapping;
export {};
import { LogicInput, LogicWrapper, BuiltLogic } from '../types';
export declare function useKea(input: LogicInput, deps?: any[]): LogicWrapper;
export declare function useKea(input: LogicInput, deps?: never[]): LogicWrapper;
export declare function useValues<L extends BuiltLogic | LogicWrapper>(logic: L): L['values'];

@@ -4,0 +4,0 @@ export declare function useAllValues<L extends BuiltLogic | LogicWrapper>(logic: L): L['values'];

@@ -26,3 +26,3 @@ import { Reducer, Store, Action as ReduxAction, Middleware, StoreEnhancer, compose, AnyAction } from 'redux';

pathString: string;
props: Props;
props: any;
propTypes: Record<string, any>;

@@ -37,7 +37,4 @@ reducers: Record<string, any>;

events: PartialRecord<LogicEventType, () => void>;
__keaTypeGenInternalSelectorTypes: Record<string, (...args: any) => any>;
__keaTypeGenInternalReducerActions: Record<string, (...args: any) => {
type: string;
payload: any;
}>;
__keaTypeGenInternalSelectorTypes: Record<string, any>;
__keaTypeGenInternalReducerActions: Record<string, any>;
}

@@ -80,6 +77,6 @@ export interface BuiltLogicAdditions {

declare type ListenerDefinitionsForRecord<A extends Record<string, (...args: any) => any>> = {
[K in keyof A]?: (payload: ReturnType<A[K]>['payload'], breakpoint: BreakPointFunction, action: ReturnType<A[K]>, previousState: any) => void | Promise<void>;
[K in keyof A]?: ListenerFunction<ReturnType<A[K]>>;
};
declare type ListenerDefinitions<LogicType extends Logic> = ListenerDefinitionsForRecord<LogicType['actionCreators']> & ListenerDefinitionsForRecord<LogicType['__keaTypeGenInternalReducerActions']>;
export declare type ListenerFunction = (payload: any, breakpoint: BreakPointFunction, action: any, previousState: any) => void | Promise<void>;
export declare type ListenerFunction<A extends AnyAction = any> = (payload: A['payload'], breakpoint: BreakPointFunction, action: A, previousState: any) => void | Promise<void>;
export declare type ListenerFunctionWrapper = (action: any, previousState: any) => void;

@@ -246,7 +243,8 @@ declare type SharedListenerDefinitions = Record<string, ListenerFunction>;

whitelist: false | Record<string, boolean>;
combined: ReducerFunction;
combined: ReducerFunction | undefined;
};
store: Store;
__store: Store | undefined;
options: InternalContextOptions;
}
export {};
{
"name": "kea",
"version": "2.2.0-rc.5",
"version": "2.2.0-rc.6",
"description": "Smart front-end architecture",

@@ -5,0 +5,0 @@ "author": "Marius Andra",

@@ -24,3 +24,3 @@ import { getContext } from '../../context'

// connected to the listener
logic.actions[key] = (...inp) => {
logic.actions[key] = (...inp: any[]) => {
const builtAction = actionCreator(...inp)

@@ -27,0 +27,0 @@ getContext().run.heap.push({ type: 'action', action: builtAction, logic })

import { addConnection } from '../shared/connect'
import { Logic, LogicInput } from '../../types'
import { BuiltLogic, Logic, LogicInput, LogicWrapper, LogicWrapperAdditions, Selector } from '../../types'

@@ -52,10 +52,10 @@ /*

}
if (otherLogic._isKea) {
otherLogic = otherLogic(props)
if ((otherLogic as LogicWrapper)._isKea) {
otherLogic = (otherLogic as LogicWrapper)(props)
}
if (otherLogic._isKeaBuild) {
addConnection(logic, otherLogic)
logic.actionCreators[to] = otherLogic.actionCreators[from]
if ((otherLogic as BuiltLogic)._isKeaBuild) {
addConnection(logic, otherLogic as BuiltLogic)
logic.actionCreators[to] = (otherLogic as BuiltLogic).actionCreators[from]
} else {
logic.actionCreators[to] = otherLogic[from]
logic.actionCreators[to] = (otherLogic as Record<string, any>)[from]
}

@@ -83,20 +83,21 @@

if (otherLogic._isKea) {
otherLogic = otherLogic(props)
if ((otherLogic as LogicWrapper)._isKea) {
otherLogic = (otherLogic as LogicWrapper)(props)
}
if (otherLogic._isKeaBuild) {
addConnection(logic, otherLogic)
logic.selectors[to] = from === '*' ? otherLogic.selector : otherLogic.selectors[from]
if ((otherLogic as BuiltLogic)._isKeaBuild) {
addConnection(logic, otherLogic as BuiltLogic)
logic.selectors[to] = (from === '*'
? (otherLogic as BuiltLogic).selector
: (otherLogic as BuiltLogic).selectors[from]) as Selector
if (from !== '*' && typeof otherLogic.propTypes[from] !== 'undefined') {
logic.propTypes[to] = otherLogic.propTypes[from]
if (from !== '*' && typeof (otherLogic as BuiltLogic).propTypes[from] !== 'undefined') {
logic.propTypes[to] = (otherLogic as BuiltLogic).propTypes[from]
}
} else {
logic.selectors[to] =
from === '*'
? otherLogic
: (state, props) => {
const values = otherLogic(state, props)
return values && values[from]
}
} else if (typeof otherLogic === 'function') {
logic.selectors[to] = (from === '*'
? otherLogic
: (state, props) => {
const values = (otherLogic as Selector)(state, props)
return values && values[from]
}) as Selector
}

@@ -113,12 +114,14 @@

type LogicMapping = (Logic | BuiltLogic | LogicWrapper | Selector | Record<string, any> | string[])[]
type DeconstructedLogicMapping = [Logic | BuiltLogic | LogicWrapper | Selector | Record<string, any>, string, string][]
// input: [ logic1, [ 'a', 'b as c' ], logic2, [ 'c', 'd' ] ]
// logic: [ [logic1, 'a', 'a'], [logic1, 'b', 'c'], [logic2, 'c', 'c'], [logic2, 'd', 'd'] ]
export function deconstructMapping(mapping) {
export function deconstructMapping(mapping: LogicMapping): DeconstructedLogicMapping {
if (mapping.length % 2 === 1) {
console.error(`[KEA] uneven mapping given to connect:`, mapping)
console.trace()
return null
console.error(mapping)
throw new Error(`[KEA] Uneven mapping given to connect`)
}
const response = []
const response: DeconstructedLogicMapping = []

@@ -129,2 +132,7 @@ for (let i = 0; i < mapping.length; i += 2) {

if (!Array.isArray(array)) {
console.error(mapping)
throw new Error('[KEA] Invalid mapping given to connect. Make sure every second element is an array!')
}
for (let j = 0; j < array.length; j++) {

@@ -131,0 +139,0 @@ if (array[j].includes(' as ')) {

@@ -8,13 +8,13 @@ import { Logic, LogicEventType, LogicInput } from '../../types'

Object.keys(events).forEach((key) => {
const event = events[key]
const event = events[key as LogicEventType]
const newEvent = Array.isArray(event) ? () => event.forEach((e) => e()) : event
if (logic.events[key]) {
const oldEvent = logic.events[key]
logic.events[key] = () => {
oldEvent()
if (logic.events[key as LogicEventType]) {
const oldEvent = logic.events[key as LogicEventType]
logic.events[key as LogicEventType] = () => {
oldEvent && oldEvent()
newEvent && newEvent()
}
} else if (newEvent) {
logic.events[key] = newEvent
logic.events[key as LogicEventType] = newEvent
}

@@ -21,0 +21,0 @@ })

@@ -20,3 +20,4 @@ /*

*/
import { Logic, LogicInput } from '../../types'
import { Logic, LogicInput, ReducerFunction } from '../../types'
import { AnyAction } from 'redux'

@@ -35,3 +36,3 @@ export function createReducers(logic: Logic, input: LogicInput): void {

let initialValue
let initialValue: any
let reducer

@@ -60,3 +61,3 @@ let type

if (typeof logic.defaults['*'] === 'function') {
logic.defaults[key] = (state, props) => {
logic.defaults[key] = (state: any, props: any) => {
const v = logic.defaults['*'](state, props)[key]

@@ -107,3 +108,4 @@ return typeof v === 'undefined' ? initialValue : typeof v === 'function' ? v(state, props) : v

funReducer && mapReducer
? (state, action, fullState) => mapReducer(funReducer(state, action, fullState), action, fullState)
? (state: any, action: AnyAction, fullState: any) =>
mapReducer(funReducer(state, action, fullState), action, fullState)
: mapReducer || funReducer

@@ -115,3 +117,3 @@

function createFunctionReducer(functions, defaultValue, key, logic) {
function createFunctionReducer(functions: ReducerFunction[], defaultValue: any, key: string, logic: Logic) {
if (functions.length === 0) {

@@ -121,3 +123,3 @@ return null

return (state, action, fullState) => {
return (state: any, action: AnyAction, fullState: any) => {
if (typeof state === 'undefined') {

@@ -132,3 +134,8 @@ state = getDefaultState(defaultValue, fullState, key, logic)

// create reducer function from such an object { [action]: (state, payload) => state }
function createMappingReducer(mapping, defaultValue, key, logic) {
function createMappingReducer(
mapping: Record<string, (state: any, payload: any, meta?: any) => any>,
defaultValue: any,
key: string,
logic: Logic,
) {
if (Object.keys(mapping).length === 0) {

@@ -148,3 +155,3 @@ return null

return (state, action, fullState) => {
return (state: any, action: AnyAction, fullState: any) => {
if (typeof state === 'undefined') {

@@ -162,3 +169,3 @@ state = getDefaultState(defaultValue, fullState, key, logic)

function getDefaultState(defaultValue, fullState, key, logic) {
function getDefaultState(defaultValue: any, fullState: any, key: any, logic: Logic) {
if (typeof defaultValue === 'function') {

@@ -165,0 +172,0 @@ if (fullState) {

@@ -11,3 +11,3 @@ import { getContext, setPluginContext, getPluginContext } from '../context'

} from '../types'
import { Store } from 'redux'
import { MiddlewareAPI } from 'redux'

@@ -64,4 +64,5 @@ /* usage:

const newListeners: Record<string, ListenerFunction> =
typeof input.listeners === 'function' ? input.listeners(fakeLogic) : input.listeners
const newListeners = (typeof input.listeners === 'function'
? input.listeners(fakeLogic)
: input.listeners) as Record<string, ListenerFunction>

@@ -103,3 +104,3 @@ logic.listeners = {

const breakpoint: BreakPointFunction = (ms?: number) => {
const breakpoint = (ms?: number): Promise<void> | void => {
if (typeof ms !== 'undefined') {

@@ -116,3 +117,3 @@ return new Promise((resolve) => setTimeout(resolve, ms)).then(() => {

try {
response = listener(action.payload, breakpoint, action, previousState)
response = listener(action.payload, breakpoint as BreakPointFunction, action, previousState)

@@ -177,3 +178,3 @@ if (response && response.then && typeof response.then === 'function') {

beforeReduxStore(options: CreateStoreOptions): void {
options.middleware.push((store: Store) => (next) => (action) => {
options.middleware.push((store: MiddlewareAPI) => (next) => (action) => {
const previousState = store.getState()

@@ -180,0 +181,0 @@ const response = next(action)

@@ -181,3 +181,3 @@ import { getContext } from '../context'

const children = {}
const children: Record<string, any> = {}

@@ -207,3 +207,3 @@ Object.keys(treeNode).forEach((key) => {

let stateChanged = Object.keys(state).length !== reducerKeys.length
const nextState = {}
const nextState: Record<string, any> = {}

@@ -234,3 +234,3 @@ for (let i = 0; i < reducerKeys.length; i++) {

regenerateCombinedReducer()
return (state = defaultState, action) => getContext().reducers.combined(state, action, state)
return (state = defaultState, action) => (getContext().reducers.combined as ReducerFunction)(state, action, state)
}

@@ -9,4 +9,4 @@ import { createStore, applyMiddleware, compose, Store, StoreEnhancer } from 'redux'

const reduxDevToolsCompose =
typeof window !== 'undefined' && window['__REDUX_DEVTOOLS_EXTENSION_COMPOSE__']
? window['__REDUX_DEVTOOLS_EXTENSION_COMPOSE__']
typeof window !== 'undefined' && (window as any)['__REDUX_DEVTOOLS_EXTENSION_COMPOSE__']
? (window as any)['__REDUX_DEVTOOLS_EXTENSION_COMPOSE__']
: compose

@@ -17,3 +17,3 @@

const defaultOptions = (): CreateStoreOptions => ({
paths: undefined,
paths: [],
reducers: {},

@@ -64,3 +64,3 @@ preloadedState: undefined,

options.paths.forEach((pathStart) => {
context.reducers.whitelist[pathStart] = true
;(context.reducers.whitelist as Record<string, any>)[pathStart] = true
initRootReducerTree(pathStart)

@@ -67,0 +67,0 @@ })

@@ -28,3 +28,3 @@ import { Reducer, Store, Action as ReduxAction, Middleware, StoreEnhancer, compose, AnyAction } from 'redux'

pathString: string
props: Props
props: any
propTypes: Record<string, any>

@@ -40,4 +40,4 @@ reducers: Record<string, any>

__keaTypeGenInternalSelectorTypes: Record<string, (...args: any) => any>
__keaTypeGenInternalReducerActions: Record<string, (...args: any) => { type: string; payload: any }>
__keaTypeGenInternalSelectorTypes: Record<string, any>
__keaTypeGenInternalReducerActions: Record<string, any>
}

@@ -127,8 +127,3 @@

type ListenerDefinitionsForRecord<A extends Record<string, (...args: any) => any>> = {
[K in keyof A]?: (
payload: ReturnType<A[K]>['payload'],
breakpoint: BreakPointFunction,
action: ReturnType<A[K]>,
previousState: any,
) => void | Promise<void>
[K in keyof A]?: ListenerFunction<ReturnType<A[K]>>
}

@@ -139,6 +134,6 @@

export type ListenerFunction = (
payload: any,
export type ListenerFunction<A extends AnyAction = any> = (
payload: A['payload'],
breakpoint: BreakPointFunction,
action: any,
action: A,
previousState: any,

@@ -360,8 +355,11 @@ ) => void | Promise<void>

whitelist: false | Record<string, boolean>
combined: ReducerFunction
combined: ReducerFunction | undefined
}
// getter that always returns something
store: Store
// the created store if present
__store: Store | undefined
options: InternalContextOptions
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc