This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@NgModule({ | |
... | |
imports: [ | |
AkitaNgEffectsModule.forRoot([TodoEffects]), | |
], | |
... | |
}) | |
export class AppModule { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.scss'] | |
}) | |
export class AppComponent implements OnInit{ | |
currentTodo = "" | |
todos$: Observable<Todo[]> | |
constructor( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export namespace TodoActions { | |
export const loadTodos = createAction('[Todo] Load Todo') | |
export const addTodo = createAction("[Todo] Add Todo", props<{todo: Todo}>()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable() | |
export class TodoEffects { | |
constructor( | |
private actions$: Actions, | |
private todoService: TodoService, | |
) { | |
} | |
loadTodos$ = createEffect(() => this.actions$.pipe( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Effect({ dispatch: true }) | |
addTodo$ = this.actions$.pipe( | |
ofType(TodoActions.addTodo), | |
tap(({ todo }) => this.todoStore.add(todo)), | |
map(({ todo }) => SnackbarActions.showSnackbar({ message: `Item has been added ${todo.title}` })) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { isFunction } from 'lodash-es'; | |
// todo may remove SymbolConstructor.iterator from item type | |
// record callbacks | |
type CallbackRecord<SourceItem, SourceKey, DictItem, DictKey> = | |
(item: SourceItem, key: SourceKey, index: number) => [DictKey, DictItem] | |
// array callbacks | |
type CallbackArray<SourceItem, DictItem, DictKey> = | |
(item: SourceItem, index: number) => [DictKey, DictItem] |