View avoid-mobx-auto-observable.test.ts
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 { makeAutoObservable } from 'mobx'; | |
import { avoidMobxAutoObservable } from './avoid-mobx-auto-observable'; | |
import { types } from 'util'; | |
test('avoidMobxAutoObservable allows to avoid Mobx auto conversion', () => { | |
class Store { | |
constructor(public dependency: object) { | |
makeAutoObservable(this); | |
} | |
} |
View maco-so-setup.sh
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
// turn off https://intellij-support.jetbrains.com/hc/en-us/articles/360005137400-Cmd-Shift-A-hotkey-opens-Terminal-with-apropos-search-instead-of-the-Find-Action-dialog | |
brew install git node@16 php@8 | |
pecl install xdebug && php -m | grep xdebug | |
// cp .id_rsa and .id_rsa.pub |
View counter.test.ts
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 { TimeTrackerStore } from './time-tracker-store'; | |
import { action, makeAutoObservable } from 'mobx'; | |
class Counter { | |
value = 0; | |
intervalId?: NodeJS.Timer; | |
constructor() { | |
makeAutoObservable(this); | |
} |
View install-fish.sh
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
# Fix inotify issue: https://stackoverflow.com/a/56156015 |
View classes.ts
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 class PlayerStore { | |
song?: Song; | |
isPlaying = false; | |
constructor() { | |
makeAutoObservable(this); | |
} | |
playSong(song: Song) { | |
this.song = song; |
View mobx-6-cache.js
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 UsersStore { | |
isLoaded = false; | |
users = []; | |
constructor() { | |
makeAutoObservable(this) | |
} | |
loadUsers() { | |
if (this.isLoaded) { |
View gist:d874ad358bf7b124f725e0abef2132d0
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
Ссылки: | |
- Лишний ререндер: https://codesandbox.io/s/usecontext-problem-b6evb | |
- Переизобретают Mobx с массой ограничений: https://habr.com/ru/post/546124/ | |
- Разработчики из Atlassian не смогли переписать react-beautiful-dnd с Redux на контекст из-за проблем с перформансом: https://github.com/atlassian/react-beautiful-dnd/issues/1576#issuecomment-549643226 |
View mobx-reuse-store.ts
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 ListStore<T> { | |
isLoading = false; | |
list: T[] = []; | |
constructor(loadList: () => Promise<T[]>) { | |
makeAutoObservable(this) | |
} | |
loadList() { | |
this.isLoading = true; |
View di-container.ts
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 { assert } from "ts-essentials"; | |
export class Container { | |
private services = new Map<string, object>(); | |
private factories = new Map<string, (container: Container) => object>(); | |
set(key: string, factory: (container: Container) => object) { | |
this.factories.set(key, factory); | |
} |
View mobx.js
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
const store = makeAutoObservable({ | |
shop: { | |
taxPercent: 8, | |
items: [ | |
{ name: 'apple', value: 1.20 }, | |
{ name: 'orange', value: 0.95 }, | |
] | |
}, | |
get subtotal() { | |
return this.shop.items.reduce((acc, item) => acc + item.value, 0); |
NewerOlder