Migrate from NgRx Ducks < 7.3 (Legacy)

This section is about the older API of NgRx Ducks. If you use a version smaller than 7.3 this article shows an overview about how you can update to the Decorator-API (deprecated).

Please note. This article has nothing to do with the current API. It exists for developers using a very old Version of NgRx Ducks (<7.3) who need an overview about the changes in the API.

The Upgrade path described here is also deprecated.

Migrate to Decorator API

Duck Class

BEFORE

export class Counter {
add(state: number, payload: number): number {
return state + payload;
}
}
export const counterAction = wireUpActions(Counter, {
add: '[Counter] Add value'
});

AFTER

@Ducksify<number>({
initialState: 0
})
export class Counter {
@Action('[Counter] Add value')
add(state: number, payload: number): number {
return state + payload;
}
}

Provider

BEFORE

import { createDucks } from '@co-it/ngrx-ducks';
@NgModule({
providers: [
{
provide: Counter,
useFactory: function(store) {
return createDucks(counterActions, store);
},
deps: [Store]
}
]
})
export class SomeModule {}

AFTER

Generate Reducer

BEFORE

import { createReducerFrom } from '@co-it/ngrx-ducks';
import { counterActions } from './counter.ducks';
export function reducer(state = initialState, action: Action): CounterSlice {
return createReducerFrom(counterActions)(state, action);
}

AFTER

import { reducerFrom } from '@co-it/ngrx-ducks';
import { Counter } from './counter.duck';
// ⚠ No need for initialState since @InitialState already provides it.
export function reducer(state, action: Action): CounterSlice {
return reducerFrom(Counter)(state, action);
}

Inject a Duck

BEFORE

@Component({
/* ... */
})
export class CounterComponent {
constructor(@Inject(Counter) private counter: Ducks<Counter>) {}
}

AFTER

@Component({
/* ... */
})
export class CounterComponent {
// "Duck<T>" naming has change to singular.
constructor(@Inject(Counter) private counter: Duck<Counter>) {
// DEPRECATED
counter.add.plain(1);
// REPLACEMENT
counter.add.action(1);
}
}

Deprecations

Deprecated Function/Method

Replacement

wireUpActions

@Action & @InitialState

createDucks

ducksify

createReducerFrom

reducerFrom

Ducks

Duck

Duck

[method].plain()

[method].action()