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
function todoStore() { | |
const allTodos = signal<ToDo[]>( | |
JSON.parse(localStorage.getItem("todos") ?? "[]") | |
); | |
const query = signal(""); | |
const newTodoName = signal(""); | |
const showCompletedTodos = signal(false); | |
const todos = computed(() => { | |
return allTodos().filter((todo) => { | |
return ( |
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: 'my-component', | |
templateUrl: './my.component.html', | |
}) | |
export class MyComponent implements OnInit { | |
ngOnInit() { | |
fromEvent(document.body, 'click') | |
.pipe(take(10)) | |
.subscribe(console.log); | |
} |
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
of(1, 2, 3, 4).pipe(take(3)).subscribe(console.log); |
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
fromEvent(document.querySelector('input'), 'input').pipe( | |
debounceTime(300), | |
map(event => (event.target as HTMLInputElement).value), | |
switchMap(query => getData(query).pipe( | |
switchAll(), | |
map(({firstName, lastName}) => firstName + ' ' + lastName), | |
toArray(), | |
)), | |
).subscribe(console.log); |
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
fromEvent(document.querySelector('input'), 'input').pipe( | |
debounceTime(300), | |
map(event => (event.target as HTMLInputElement).value), | |
switchMap(query => getData(query)), | |
switchAll(), | |
map(({firstName, lastName}) => firstName + ' ' + lastName), | |
toArray(), | |
).subscribe(console.log); |
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
fromEvent(document.querySelector('input'), 'input').pipe( | |
debounceTime(300), | |
map(event => (event.target as HTMLInputElement).value), | |
switchMap(query => getData(query)), | |
).subscribe(console.log); |
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
of(1, 2, 3).pipe(toArray()).subscribe(console.log); |
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
withLatestFrom(this.control.valueChanges.pipe(startWith(null))); |
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: 'my-component', | |
template: '<div><input [formControl]="control"/></div>', | |
}) | |
export class MyComponent implements OnInit { | |
control = new FormControl(''); | |
ngOnInit() { | |
fromEvent(document.body, 'click').pipe( | |
withLatestFrom(this.control.valueChanges), |
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
class ActionNames { | |
private static names = new Set<string>(); | |
static create(name: string): string { | |
if (ActionNames.names.has(name)) { | |
throw new Error('An Action with this type already exists!'); | |
} | |
ActionNames.names.add(name); | |
return name; | |
} |
NewerOlder