Skip to content

chore: bump deps #467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"extends": [
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"prettier/@typescript-eslint"
"prettier"
],
"globals": {
"Atomics": "readonly",
Expand All @@ -27,7 +26,7 @@
"@typescript-eslint/no-use-before-define": ["error", { "functions": false, "classes": false }],
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/ban-ts-comment": "off",
"no-console": ["error", { "allow": ["warn", "error"] }]
},
"settings": {
Expand Down
24 changes: 12 additions & 12 deletions demo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ class Count extends Ayanami<State> {
}
}

const InputComponent = React.memo(() => {
const [input, actions] = useAyanami(Count, { selector: (state) => state.input })

return (
<div>
<h3>{input}</h3>
<input value={input} onChange={(e) => actions.changeInput(e.target.value)} />
</div>
)
})
InputComponent.displayName = 'InputComponent'

function CountComponent() {
const [{ count, input }, actions] = useAyanami(Count)
const [{ tips }] = useAyanami(Tips)
Expand All @@ -93,16 +105,4 @@ function CountComponent() {
)
}

const InputComponent = React.memo(() => {
const [input, actions] = useAyanami(Count, { selector: (state) => state.input })

return (
<div>
<h3>{input}</h3>
<input value={input} onChange={(e) => actions.changeInput(e.target.value)} />
</div>
)
})
InputComponent.displayName = 'InputComponent'

ReactDOM.render(<CountComponent />, document.querySelector('#app'))
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@
"@types/lodash": "^4.14.136",
"@types/node": "^12.6.9",
"@types/react": "^17.0.3",
"@types/react-dom": "^16.8.5",
"@types/react-test-renderer": "^16.8.3",
"@types/react-dom": "^17.0.2",
"@types/react-test-renderer": "^17.0.1",
"@types/shallowequal": "^1.1.1",
"@typescript-eslint/eslint-plugin": "^2.1.0",
"@typescript-eslint/parser": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"codecov": "^3.5.0",
"eslint": "6.6.0",
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-react": "^7.14.3",
"eslint": "7.22.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-react": "^7.21.5",
"husky": "^4.3.0",
"immer": "^8.0.1",
"jest": "^24.8.0",
Expand All @@ -85,21 +85,21 @@
"npm-run-all": "^4.1.5",
"parcel": "^1.12.3",
"prettier": "^2.2.1",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-test-renderer": "^16.8.6",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-test-renderer": "^17.0.1",
"reflect-metadata": "^0.1.13",
"rxjs": "^6.5.2",
"shx": "^0.3.2",
"ts-jest": "^24.0.2",
"tslib": "^1.10.0",
"typescript": "^3.5.3"
"tslib": "^2.1.0",
"typescript": "^4.2.3"
},
"peerDependencies": {
"@asuka/di": "^0.2.0",
"immer": "^3.2.0",
"immer": "^8.0.1",
"lodash": "^4.17.15",
"react": "^16.8.6",
"react": "^17.0.1",
"reflect-metadata": "^0.1.13",
"rxjs": "^6.5.2"
}
Expand Down
6 changes: 3 additions & 3 deletions src/connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ type ConnectedComponent<P, S, A> = React.FunctionComponent<Omit<P, keyof S | key
type ConnectComponent<S, A> = <P>(Component: React.ComponentType<P>) => ConnectedComponent<P, S, A>

export interface ComponentConnectedWithAyanami<M extends Ayanami<S>, S> {
(): ConnectComponent<{}, {}>
(): ConnectComponent<Record<string, unknown>, Record<string, unknown>>

<MS>(mapStateToProps: (state: S) => MS): ConnectComponent<MS, {}>
<MS>(mapStateToProps: (state: S) => MS): ConnectComponent<MS, Record<string, unknown>>

<MS, MA>(
mapStateToProps: (state: S) => MS,
Expand All @@ -20,7 +20,7 @@ export interface ComponentConnectedWithAyanami<M extends Ayanami<S>, S> {
<MA>(
mapStateToProps: null,
mapActionsToProps: (actions: ActionMethodOfAyanami<M, S>) => MA,
): ConnectComponent<{}, MA>
): ConnectComponent<Record<string, unknown>, MA>
}

export function connectAyanami<M extends Ayanami<S>, S>(
Expand Down
2 changes: 1 addition & 1 deletion src/core/ayanami.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export abstract class Ayanami<State> {
}
}

destroy() {
destroy(): void {
destroyIkariFrom(this)
}

Expand Down
10 changes: 8 additions & 2 deletions src/core/decorators/action-related.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ import { Ayanami } from '../ayanami'
import { ConstructorOf } from '../types'

export function createActionDecorator(symbols: ActionSymbols) {
return () => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
return () => (
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
target: any,
propertyKey: string,
descriptor: PropertyDescriptor,
): PropertyDescriptor => {
addActionName(symbols, target.constructor, propertyKey)
return descriptor
}
}

// eslint-disable-next-line @typescript-eslint/ban-types
function addActionName(symbols: ActionSymbols, constructor: Function, actionName: string) {
const decoratedActionNames = Reflect.getMetadata(symbols.decorator, constructor) || []
Reflect.defineMetadata(symbols.decorator, [...decoratedActionNames, actionName], constructor)
Expand All @@ -21,7 +27,7 @@ export function getActionNames<T extends Ayanami<any>>(
return Reflect.getMetadata(symbols.decorator, constructor) || []
}

export function getAllActionNames<T extends Ayanami<any>>(instance: T) {
export function getAllActionNames<T extends Ayanami<any>>(instance: T): (keyof T)[] {
return allActionSymbols.reduce<(keyof T)[]>(
(result, symbols) => [
...result,
Expand Down
8 changes: 6 additions & 2 deletions src/core/ikari.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ export function combineWithIkari<S>(ayanami: Ayanami<S>): Ikari<S> {
} else {
const { effects, reducers, immerReducers, defineActions } = getOriginalFunctions(ayanami)

Object.assign(ayanami, mapValues(defineActions, ({ observable }) => observable))
Object.assign(
ayanami,
mapValues(defineActions, ({ observable }) => observable),
)

return Ikari.createAndBindAt(ayanami, {
nameForLog: ayanami.constructor.name,
Expand Down Expand Up @@ -103,6 +106,7 @@ export class Ikari<State> {
// @internal
terminate$ = new Subject<typeof TERMINATE_ACTION | null>()

// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
constructor(readonly ayanami: Ayanami<State>, private readonly config: Readonly<Config<State>>) {
const [effectActions$, effectActions] = setupEffectActions(
this.config.effects,
Expand Down Expand Up @@ -158,7 +162,7 @@ export class Ikari<State> {
)
}

destroy() {
destroy(): void {
this.subscription.unsubscribe()
this.triggerActions = {}
}
Expand Down
7 changes: 6 additions & 1 deletion src/core/scope/same-scope-decorator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
export const SameScopeMetadataKey = Symbol('SameScopeInjectionParams')

export const SameScope = () => (target: any, _propertyKey: string, parameterIndex: number) => {
export const SameScope = () => (
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
target: any,
_propertyKey: string,
parameterIndex: number,
): void => {
let sameScopeInjectionParams: boolean[] = []
if (Reflect.hasMetadata(SameScopeMetadataKey, target)) {
sameScopeInjectionParams = Reflect.getMetadata(SameScopeMetadataKey, target)
Expand Down
1 change: 1 addition & 0 deletions src/core/scope/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ function getInstanceFrom<T>(constructor: ConstructorOf<T>, scope: Scope): T | un
return scopeMap && scopeMap.get(scope)
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function createScopeWithRequest(req: Request, scope: any | undefined) {
if (!scope) {
return req
Expand Down
5 changes: 4 additions & 1 deletion src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import { Draft } from 'immer'
import { Ayanami } from './ayanami'

// https://stackoverflow.com/questions/55541275/typescript-check-for-the-any-type
type IfAny<T, Y, N> = 0 extends (1 & T) ? Y : N
type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N

type IsAny<T> = IfAny<T, true, false>

// https://stackoverflow.com/questions/55542332/typescript-conditional-type-with-discriminated-union
type IsVoid<T> = IsAny<T> extends true ? false : [T] extends [void] ? true : false

// using class type to avoid conflict with user defined params
// eslint-disable-next-line @typescript-eslint/no-unused-vars
class ArgumentsType<_Arguments extends any[]> {}

export type ActionMethod<
Expand Down Expand Up @@ -43,6 +44,7 @@ export interface ReducerAction<State> {
readonly nextState: State
}

// eslint-disable-next-line @typescript-eslint/ban-types
type UnpackEffectFunctionArguments<T extends Function> = T extends (
...payload: infer Arguments
) => Observable<EffectAction>
Expand All @@ -61,6 +63,7 @@ type UnpackEffectPayload<Func, State> = Func extends () => Observable<EffectActi
? UnpackEffectFunctionArguments<Func>
: never

// eslint-disable-next-line @typescript-eslint/ban-types
type UnpackReducerFunctionArguments<T extends Function> = T extends (
state: any,
...payload: infer Arguments
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils/get-effect-action-factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Ayanami } from '../ayanami'
import { EffectAction } from '../types'
import { getAllActionNames } from '../decorators'

export function getEffectActionFactories(target: Ayanami<any>) {
export function getEffectActionFactories(target: Ayanami<any>): any {
return getAllActionNames(target).reduce(
(result: any, name: string) => ({
...result,
Expand Down
15 changes: 9 additions & 6 deletions src/core/utils/get-original-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import { effectSymbols, reducerSymbols, immerReducerSymbols, defineActionSymbols
const getOriginalFunctionNames = (ayanami: Ayanami<any>) => ({
effects: getActionNames(effectSymbols, ayanami.constructor as ConstructorOf<Ayanami<any>>),
reducers: getActionNames(reducerSymbols, ayanami.constructor as ConstructorOf<Ayanami<any>>),
defineActions: getActionNames(defineActionSymbols, ayanami.constructor as ConstructorOf<
Ayanami<any>
>),
immerReducers: getActionNames(immerReducerSymbols, ayanami.constructor as ConstructorOf<
Ayanami<any>
>),
defineActions: getActionNames(
defineActionSymbols,
ayanami.constructor as ConstructorOf<Ayanami<any>>,
),
immerReducers: getActionNames(
immerReducerSymbols,
ayanami.constructor as ConstructorOf<Ayanami<any>>,
),
})

const transformDefineActions = (actionNames: string[]): OriginalDefineActions => {
Expand All @@ -37,6 +39,7 @@ const transformDefineActions = (actionNames: string[]): OriginalDefineActions =>
return result
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const getOriginalFunctions = (ayanami: Ayanami<any>) => {
const { effects, reducers, immerReducers, defineActions } = getOriginalFunctionNames(ayanami)

Expand Down
9 changes: 0 additions & 9 deletions src/hooks/shallow-equal.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/hooks/use-subscribe-ayanami-state.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react'
import { Subscription } from 'rxjs'
import identity from 'lodash/identity'
import { shallowEqual } from './shallow-equal'
import shallowEqual from 'shallowequal'
import { Ayanami } from '../core'

export function useSubscribeAyanamiState<M extends Ayanami<S>, S, U = S>(
Expand Down
10 changes: 5 additions & 5 deletions src/redux-devtools-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ interface DevTools {
}

interface GlobalState {
[modelName: string]: object
[modelName: string]: Record<string, unknown>
}

const FakeReduxDevTools = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
connect: (_config: object) => ({ send: noop, init: noop }),
connect: (_config: Record<string, unknown>) => ({ send: noop, init: noop }),
}

const ReduxDevTools =
Expand All @@ -34,18 +34,18 @@ const getDevTools = (() => {

let isEnableLog = false

export function enableReduxLog() {
export function enableReduxLog(): void {
isEnableLog = true
}

export function disableReduxLog() {
export function disableReduxLog(): void {
isEnableLog = false
}

export function logStateAction(
namespace: string,
infos: { actionName: string; params: string; state?: any },
) {
): void {
if (isEnableLog) {
const action = {
type: `${namespace}/${infos.actionName}`,
Expand Down
3 changes: 2 additions & 1 deletion src/ssr/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface SSREffectOptions<Payload> {
skipFirstClientDispatch?: boolean
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function SSREffect<T, Payload>(options?: SSREffectOptions<Payload>) {
const { payloadGetter, skipFirstClientDispatch } = {
payloadGetter: undefined,
Expand All @@ -53,7 +54,7 @@ export function SSREffect<T, Payload>(options?: SSREffectOptions<Payload>) {
addDecorator(target, method, payloadGetter)
if (!isSSREnabled() && skipFirstClientDispatch) {
const originalValue = descriptor.value
descriptor.value = function(
descriptor.value = function (
this: any,
action$: Observable<Payload>,
state$?: Observable<any>,
Expand Down
2 changes: 1 addition & 1 deletion src/ssr/flag.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const isSSREnabled = () => {
export const isSSREnabled = (): boolean => {
return typeof process.env.ENABLE_AYANAMI_SSR !== 'undefined'
? process.env.ENABLE_AYANAMI_SSR === 'true'
: typeof process !== 'undefined' &&
Expand Down
3 changes: 2 additions & 1 deletion src/ssr/ssr-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const configSets = new Set<string>()
export const moduleNameKey = Symbol.for('__MODULE__NAME__')
export const globalKey = Symbol.for('__GLOBAL_MODULE_CACHE__')

export const SSRModule = (config: string | InjectableConfig & { name: string }) => {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const SSRModule = (config: string | (InjectableConfig & { name: string })) => {
const injectableConfig: InjectableConfig = { providers: [] }
let name: string
if (typeof config === 'string') {
Expand Down
3 changes: 2 additions & 1 deletion test/specs/effect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Count extends Ayanami<CountState> {
count: 0,
}

// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
constructor(readonly tips: Tips) {
super()
}
Expand Down Expand Up @@ -105,7 +106,7 @@ describe('Effect spec:', () => {

describe('Error handles', () => {
it(`Error won't affect the main state$`, () => {
const errorLog = jest.spyOn(console, 'error').mockImplementation(() => {})
const errorLog = jest.spyOn(console, 'error').mockImplementation(() => void 0)
countActions.error()
expect(errorLog.mock.calls.length).toBe(1)
errorLog.mockRestore()
Expand Down
Loading