-
Notifications
You must be signed in to change notification settings - Fork 9
[2025-10-03] Czy wiesz, że za pomocą operatora shareReplay możesz cac… #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…he'ować dane z observable?
| - observable | ||
| --- | ||
|
|
||
| Często zdarza się, że nie chcemy za każdym razem ponownie wykonywać całej logiki z danego *Observable* — |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Observable to nazwa klasy dałbym w apostrofach żeby się sformatowało jak kod
| image: /assets/img/posts/2025-10-03-czy-wiesz-ze-za-pomoca-operatora-sharereplay-mozesz-cache-owac-dane-z-observable/thumbnail.webp | ||
| tags: | ||
| - angular | ||
| - rxjs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rxjs dałbym jako pierwszy tag (on się wyświetli na liście)
| --- | ||
|
|
||
| Często zdarza się, że nie chcemy za każdym razem ponownie wykonywać całej logiki z danego *Observable* — | ||
| zamiast tego wolimy przechować jego wynik w pamięci. W Angularze (i ogólnie w RxJS) możemy to zrobić za pomocą operatora **`shareReplay`**. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
przy shareReplay zostawiłbym same apostrofy (nie przekombinowujmy z formatowaniem)
|
|
||
| ## Przykład użycia | ||
| W przykładzie poniżej generujemy losową liczbę. Normalnie przy każdej subskrypcji otrzymalibyśmy nowy wynik, | ||
| ale dzięki `shareReplay` obie subskrypcje dostają dokładnie tę samą wartość. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tą samą wartość
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tę wartość
| s2: 742 | ||
| ``` | ||
| ## Opcje konfiguracji | ||
| Operator `shareReplay` posiada także dodatkowe opcje do skonfigurowania. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dwukropek zamiast kropki
|
|
||
|
|
||
| ### Przykład z dodatkowymi opcjami konfiguracji | ||
| Załóżmy, że chcemy cache’ować więcej niż jedną wartość i dodatkowo kontrolować czas ich przechowywania. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wydaje mi się, że "dodatkowo" to wtrącenie i tam powinien być jakiś przecinek, ale niech się wypowie nasz specjalista od języka polskiego ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tutaj bez przecinka :D
| ```typescript | ||
| shareReplay({ bufferSize: 3, refCount: true, windowTime: 500 }) | ||
| ``` | ||
| - zostaną umieszczone w buforze 3 ostatnie wartości, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brakuje mi jakiejś części zdania przed tym wypunktowaniem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO logo angulara jest tu chybione - jeśli miałoby to być logo to raczej rxjs
| author: ptatarski | ||
| image: /assets/img/posts/2025-10-03-czy-wiesz-ze-za-pomoca-operatora-sharereplay-mozesz-cache-owac-dane-z-observable/thumbnail.webp | ||
| tags: | ||
| - angular |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wyrzuciłbym angulara z tagów
| Operator `shareReplay` posiada także dodatkowe opcje do skonfigurowania. | ||
| - `bufferSize` - określa wielkość wewnętrznego ReplaySubject (domyślnie przechowuje ostatnią wartość), | ||
| - `refCount` - określa, czy w momencie, gdy liczba subskrybentów wyniesie 0 shareReplay ma odsubskrybować się od źródłowego observable, co spowoduje wyczyszczenie cache (domyślnie false), | ||
| - `windowTime` - ograniczenie czasu przechowywanych wartości (domyślnie nie ogranicza). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ogranicza czas przechowywania wartości (czego domyślnie nie robi)
|
|
||
| ## Przykład użycia | ||
| W przykładzie poniżej generujemy losową liczbę. Normalnie przy każdej subskrypcji otrzymalibyśmy nowy wynik, | ||
| ale dzięki `shareReplay` obie subskrypcje dostają dokładnie tę samą wartość. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tę wartość
|
|
||
|
|
||
| ### Przykład z dodatkowymi opcjami konfiguracji | ||
| Załóżmy, że chcemy cache’ować więcej niż jedną wartość i dodatkowo kontrolować czas ich przechowywania. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tutaj bez przecinka :D
…he'ować dane z observable?