Skip to content

Instantly share code, notes, and snippets.

View yackinn's full-sized avatar

Yannick Boetzkes yackinn

View GitHub Profile
@yackinn
yackinn / create-dictionary.ts
Last active September 30, 2021 08:33
Create dictionary function
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]
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit{
currentTodo = ""
todos$: Observable<Todo[]>
constructor(
@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}` }))
);
export namespace TodoActions {
export const loadTodos = createAction('[Todo] Load Todo')
export const addTodo = createAction("[Todo] Add Todo", props<{todo: Todo}>())
}
@Injectable()
export class TodoEffects {
constructor(
private actions$: Actions,
private todoService: TodoService,
) {
}
loadTodos$ = createEffect(() => this.actions$.pipe(
@yackinn
yackinn / app.module.ts
Last active January 18, 2021 22:08
Akita effects example
@NgModule({
...
imports: [
AkitaNgEffectsModule.forRoot([TodoEffects]),
],
...
})
export class AppModule {
}