Skip to content

Commit

Permalink
enable esm & upgrade typescript (#5)
Browse files Browse the repository at this point in the history
* enable esm & upgrade typescript

* restore saga and to be fixed

* clean

* clean

* fix deps

* deps

* 0.11.2

* fix deps

* 0.11.3

* fix redux-observable (redux-observable/redux-observable#751 (comment))

* fix smoke testing

* 0.11.4

* fix smoke testing

* 0.11.5
  • Loading branch information
huan authored Sep 18, 2021
1 parent 774a1cf commit d48bf58
Show file tree
Hide file tree
Showing 71 changed files with 447 additions and 342 deletions.
File renamed without changes.
8 changes: 4 additions & 4 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ jobs:
- name: Install Dependencies
run: npm install

- name: Generate Version
run: ./scripts/generate-version.sh
- name: Generate Package JSON
run: ./scripts/generate-package-json.sh

- name: Pack Testing
run: ./scripts/npm-pack-testing.sh
Expand All @@ -68,8 +68,8 @@ jobs:
- name: Install Dependencies
run: npm install

- name: Generate Version
run: ./scripts/generate-version.sh
- name: Generate Package JSON
run: ./scripts/generate-package-json.sh

- name: Set Publish Config
run: ./scripts/package-publish-config-tag.sh
Expand Down
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ In order to build a fully modularized Ducks, we define the **Ducksify** extensio

## Requirements

Node.js v12+, or Browser with ES2019 Support
Node.js v14+, or Browser with ES2020 Support

## Install

Expand Down Expand Up @@ -181,7 +181,7 @@ export default function reducer (state = initialState, action) {

```ts
import { Ducks } from 'ducks'
import * as counterDuck from './counter'
import * as counterDuck from './counter.js'
const ducks = new Ducks({ counter: counterDuck })
const counter = ducks.ducksify(counterDuck)
Expand Down Expand Up @@ -236,7 +236,9 @@ It shows that:
1. Ducks supports `redux-observable` and `redux-saga` out-of-the-box with zero configuration.
1. How to stick with the best practices to write a redux reducer bundle by following the ducks modular proposal.

Talk is cheap, show me the code: the following example code can be found at [examples/quack.ts](examples/quack.ts), you can try it by running the following commands:
### Talk is cheap, show me the code

The following example code can be found at [examples/quack.ts](examples/quack.ts), you can try it by running the following commands:

```sh
git clone [email protected]:huan/ducks.git
Expand All @@ -250,10 +252,10 @@ npm start
import { createStore } from 'redux'
import { Duck, Ducks } from 'ducks'
import * as counterDuck from './counter' // Vanilla Duck: +1
import * as dingDongDuck from './ding-dong' // Observable Middleware
import * as pingPongDuck from './ping-pong' // Saga Middleware
import * as switcherDuck from './switcher' // Type Safe Actions: ON/OFF
import * as counterDuck from './counter.js' // Vanilla Duck: +1
import * as dingDongDuck from './ding-dong.js' // Observable Middleware
import * as pingPongDuck from './ping-pong.js' // Saga Middleware
import * as switcherDuck from './switcher.js' // Type Safe Actions: ON/OFF
const ducks = new Ducks({
counter : counterDuck,
Expand Down Expand Up @@ -324,12 +326,12 @@ Example:
`Duck` counter example from our [examples](examples/counter/index.ts)

```ts
import * as actions from './actions'
import * as operations from './operations'
import * as selectors from './selectors'
import * as types from './types'
import * as actions from './actions.js'
import * as operations from './operations.js'
import * as selectors from './selectors.js'
import * as types from './types.js'
import reducer from './reducers'
import reducer from './reducers.js'
export {
actions,
Expand All @@ -347,7 +349,7 @@ The `Ducks` class is the manager for `Duck`s and connecting them to the Redux St

```ts
import { Ducks } from 'ducks'
import * as counterApi from './counter'
import * as counterApi from './counter.js'
const ducks = new Ducks({
counter: counterApi,
Expand Down Expand Up @@ -426,7 +428,7 @@ const store = createStore(
For example:
```ts
import * as counterDuck from './counter'
import * as counterDuck from './counter.js'

const ducks = new Ducks({ counter: counterDuck })
const store = ducks.configureStore()
Expand Down Expand Up @@ -467,7 +469,7 @@ To make sure your Ducks Api is following the specification of the [ducks modular
```ts
import { validateDuck } from 'ducks'
import * as counterDuck from './counter'
import * as counterDuck from './counter.js'

validateDuck(counterDuck) // will throw if the counterApi is invalid.
```
Expand Down Expand Up @@ -562,6 +564,7 @@ Don't store system state, store events that brought system to this state.
### master v0.11 (Sep 2021)
1. Disable `saga` support temporary due to ([#4](https://github.com/huan/ducks/issues/4))
1. ES Modules support
### v0.10 (Jun 6, 2020)
Expand Down
2 changes: 1 addition & 1 deletion examples/counter/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import { createAction } from 'typesafe-actions'

import * as types from './types'
import * as types from './types.js'

const prepareTimes = (times = 1) => ({ times })

Expand Down
10 changes: 5 additions & 5 deletions examples/counter/index.ts → examples/counter/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
* limitations under the License.
*
*/
import * as actions from './actions'
import * as operations from './operations'
import * as selectors from './selectors'
import * as types from './types'
import * as actions from './actions.js'
import * as operations from './operations.js'
import * as selectors from './selectors.js'
import * as types from './types.js'

import reducer from './reducers'
import reducer from './reducers.js'

export {
actions,
Expand Down
4 changes: 2 additions & 2 deletions examples/counter/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
* limitations under the License.
*
*/
import { Dispatch } from 'redux'
import type { Dispatch } from 'redux'

import * as actions from './actions'
import * as actions from './actions.js'

const tap = (dispatch: Dispatch) => () => dispatch(actions.tap())

Expand Down
16 changes: 8 additions & 8 deletions examples/counter/reducers.spec.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env ts-node
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm

/**
* Ducks - https://github.com/huan/ducks
Expand All @@ -22,19 +22,19 @@ import { test } from 'tstest'

import { combineReducers } from 'redux'

import reducer from './reducers'
import reducer from './reducers.js'

import * as actions from './actions'
import * as actions from './actions.js'

test('counter reducer initial state', async t => {
let state = reducer(undefined, {} as any)
t.deepEqual(state, { total: 0 }, 'should return the initial state')
t.same(state, { total: 0 }, 'should return the initial state')

state = reducer(state, actions.tap())
t.deepEqual(state, { total: 1 }, 'should increase 1 after tap()')
t.same(state, { total: 1 }, 'should increase 1 after tap()')

state = reducer(state, actions.tap(2))
t.deepEqual(state, { total: 3 }, 'should increase 3 after tap(2)')
t.same(state, { total: 3 }, 'should increase 3 after tap(2)')
})

test('counter reducer with combineReducers()', async t => {
Expand All @@ -43,8 +43,8 @@ test('counter reducer with combineReducers()', async t => {
})

let state = combinedReducer(undefined, {} as any)
t.deepEqual(state, { counter: { total: 0 } }, 'should return the initial state')
t.same(state, { counter: { total: 0 } }, 'should return the initial state')

state = combinedReducer(state, actions.tap())
t.deepEqual(state, { counter: { total: 1 } }, 'should increase 1 after tap()')
t.same(state, { counter: { total: 1 } }, 'should increase 1 after tap()')
})
4 changes: 2 additions & 2 deletions examples/counter/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import {
createReducer,
ActionType,
} from 'typesafe-actions'
import { DeepReadonly } from 'utility-types'
import type { DeepReadonly } from 'utility-types'

import * as actions from './actions'
import * as actions from './actions.js'

const initialState: DeepReadonly<{
total: number,
Expand Down
2 changes: 1 addition & 1 deletion examples/counter/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*
*/
import { State } from './reducers'
import type { State } from './reducers.js'

const getCounter = (state: State) => () => state.total
const getMeaningOfLife = (_state: State) => (_: any) => 42
Expand Down
6 changes: 3 additions & 3 deletions examples/counter/tests.spec.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node -r ts-node/register
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm
/**
* Ducks - https://github.com/huan/ducks
*
Expand All @@ -25,9 +25,9 @@ import {

import {
validateDuck,
} from '../../src/'
} from '../../src/mod.js'

import * as duck from '.'
import * as duck from './mod.js'

validateDuck(duck)

Expand Down
2 changes: 1 addition & 1 deletion examples/ding-dong/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*
*/
import * as types from './types'
import * as types from './types.js'

const ding = () => ({ type: types.DING })
const dong = () => ({ type: types.DONG })
Expand Down
4 changes: 2 additions & 2 deletions examples/ding-dong/epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import {
mapTo,
} from 'rxjs/operators'

import * as actions from './actions'
import * as types from './types'
import * as actions from './actions.js'
import * as types from './types.js'

const dingEpic: Epic = action$ => action$.pipe(
ofType(types.DING),
Expand Down
12 changes: 6 additions & 6 deletions examples/ding-dong/index.ts → examples/ding-dong/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
* limitations under the License.
*
*/
import * as actions from './actions'
import * as epics from './epics'
import * as operations from './operations'
import * as selectors from './selectors'
import * as types from './types'
import * as actions from './actions.js'
import * as epics from './epics.js'
import * as operations from './operations.js'
import * as selectors from './selectors.js'
import * as types from './types.js'

import reducer from './reducers'
import reducer from './reducers.js'

export {
actions,
Expand Down
4 changes: 2 additions & 2 deletions examples/ding-dong/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
* limitations under the License.
*
*/
import { Dispatch } from 'redux'
import type { Dispatch } from 'redux'

import * as actions from './actions'
import * as actions from './actions.js'

const ding = (dispatch: Dispatch) => () => dispatch(actions.ding())

Expand Down
2 changes: 1 addition & 1 deletion examples/ding-dong/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import { Action, combineReducers } from 'redux'

import * as types from './types'
import * as types from './types.js'

const initialState = {
dong: 0,
Expand Down
2 changes: 1 addition & 1 deletion examples/ding-dong/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*
*/
import reducer from './reducers'
import type reducer from './reducers.js'

const getDong = (state: ReturnType<typeof reducer>) => () => state.reducer.dong

Expand Down
16 changes: 11 additions & 5 deletions examples/ding-dong/tests.spec.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node -r ts-node/register
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm
/**
* Ducks - https://github.com/huan/ducks
*
Expand All @@ -19,17 +19,23 @@
*/
import { test } from 'tstest'

import configureMockStore from 'redux-mock-store'
import reduxMockStorePkg from 'redux-mock-store'
import {
createEpicMiddleware,
combineEpics,
} from 'redux-observable'

import {
validateDuck,
} from '../../src'
} from '../../src/mod.js'

import * as duck from '.'
import * as duck from './mod.js'

/**
* Huan(202109): FIXME: CJS import problem should be fixed.
* remove `as any` when import problem fixed.
*/
const configureMockStore: typeof reduxMockStorePkg = (reduxMockStorePkg as any).default

validateDuck(duck)

Expand All @@ -52,5 +58,5 @@ test('ding -> dong', async t => {

store.dispatch(duck.actions.ding())

t.deepEqual(store.getActions(), expectedActions, 'should get the DONG after DING')
t.same(store.getActions(), expectedActions, 'should get the DONG after DING')
})
2 changes: 1 addition & 1 deletion examples/ping-pong/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*
*/
import * as types from './types'
import * as types from './types.js'

const ping = () => ({ type: types.PING })
const pong = () => ({ type: types.PONG })
Expand Down
12 changes: 6 additions & 6 deletions examples/ping-pong/index.ts → examples/ping-pong/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
* limitations under the License.
*
*/
import * as actions from './actions'
import * as operations from './operations'
import * as selectors from './selectors'
import * as types from './types'
import * as actions from './actions.js'
import * as operations from './operations.js'
import * as selectors from './selectors.js'
import * as types from './types.js'
/**
* Huan(202109): disable saga
* See: https://github.com/huan/ducks/issues/4
*/
// import * as sagas from './sagas'
// import * as sagas from './sagas.js'

import reducer from './reducers'
import reducer from './reducers.js'

export {
actions,
Expand Down
4 changes: 2 additions & 2 deletions examples/ping-pong/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
* limitations under the License.
*
*/
import { Dispatch } from 'redux'
import type { Dispatch } from 'redux'

import * as actions from './actions'
import * as actions from './actions.js'

const ping = (dispatch: Dispatch) => () => dispatch(actions.ping())

Expand Down
Loading

0 comments on commit d48bf58

Please sign in to comment.