Giter Site home page Giter Site logo

huan / ducks Goto Github PK

View Code? Open in Web Editor NEW
0.0 4.0 0.0 1.37 MB

Reducer Bundles Manager for Redux, Implemented the Ducks Modular Proposal

Home Page: https://paka.dev/npm/ducks

License: Apache License 2.0

JavaScript 39.24% Shell 2.68% TypeScript 58.08%
redux ducks redux-ecosystem-links modular-ducks redux-reducer-bundle

ducks's Issues

Protect String Literal Types in Action Types

When we define the redux action types in ducks, we will store them in a types.ts file:

const TEST = 'module/TEST'

Use export const TEST

And use import * as types from './types' in other TS module to import all the types.

In this way, the TEST can keep the string literal type as module/TEST, which is necessary for future usage.

Do NOT use export default { TEST }

In this way, the typeof TEST will become string, which will lose its string literal type.

If it lists its string literal type, then it seems more likely will cause the problem in future usage.

References

Using string constants as action type property:

please make sure to use simple string literal assignment with const. This limitation is coming from the type-system, because all the dynamic string operations (e.g. string concatenation, template strings and also object used as a map) will widen the literal type to its super-type, string. As a result this will break contextual typing for action object in reducer cases.

Property 'payload' is missing in type 'AnyAction'

Minimum reproducible code snip:

import { Reducer, AnyAction } from 'redux'

type MyAction = {
  payload: number,
  type: 'TAP',
}

const f: Reducer<any, MyAction> = (s: any, ..._: any[]) => s
const r: Reducer<any, AnyAction> = f
// r is NOT ok.
void r

The error message of r is:

Type 'Reducer<any, MyAction>' is not assignable to type 'Reducer<any, AnyAction>'.
  Types of parameters 'action' and 'action' are incompatible.
    Type 'AnyAction' is not assignable to type 'MyAction'.ts(2322)

However,

const a1: MyAction = {
  payload: 42,
  type: 'TAP',
}
const a2: AnyAction = a1
// a2 is OK
void a2

To be fixed.

Related Issues

import 'redux-saga/effects': CustomError: ERR_UNSUPPORTED_DIR_IMPORT

The Problem

When running under ES Modules mode:

$ node --no-warnings --loader=ts-node/esm ./src/ducks/ducks.spec.ts 
/Users/huan/git/huan/ducks/node_modules/ts-node/dist-raw/node-esm-resolve-implementation.js:379
    const err = new ERR_UNSUPPORTED_DIR_IMPORT(path, fileURLToPath(base));
                ^
CustomError: ERR_UNSUPPORTED_DIR_IMPORT /Users/huan/git/huan/ducks/node_modules/redux-saga/effects /Users/huan/git/huan/ducks/examples/ping-pong/sagas.ts

import {
takeEvery,
put,
} from 'redux-saga/effects'

The Workaround

To disable saga temporarily and will investigate in the future.

Promote the Ducks library

createMockStore is not a function

When running with ES Module mode, we have to:

import * as MOCK_STORE 'redux-mock-store'
const createMockStore = (MOCK_STORE.default as any).default as typeof MOCK_STORE.default

The above code will violate the Typing system (must use as any), but it works for the final code.

To be investigated.

Version

  • "redux-mock-store": "^1.5.4"
  • "@types/redux-mock-store": "^1.0.3"

Link to

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.