Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 005e034

Browse files
feat(#773): use stencil/store for notes
1 parent e92f018 commit 005e034

File tree

4 files changed

+22
-46
lines changed

4 files changed

+22
-46
lines changed

remote/src/app/components/app-notes/app-notes.tsx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,24 @@
11
import {Component, h, Listen, State} from '@stencil/core';
22

3-
import {Subscription} from 'rxjs';
3+
import notesStores from '../../stores/notes.store';
44

55
import {Remarkable} from 'remarkable';
66

7-
import {NotesService} from '../../services/notes/notes.service';
8-
97
@Component({
108
tag: 'app-notes',
11-
styleUrl: 'app-notes.scss'
9+
styleUrl: 'app-notes.scss',
1210
})
1311
export class AppNotes {
14-
private notesService: NotesService;
15-
16-
private subscription: Subscription;
12+
private destroyListener;
1713

1814
@State()
1915
private portrait: boolean = true;
2016

2117
@State()
2218
private notes: string;
2319

24-
constructor() {
25-
this.notesService = NotesService.getInstance();
26-
}
27-
2820
componentWillLoad() {
29-
this.subscription = this.notesService.watch().subscribe((element: HTMLElement) => {
21+
notesStores.onChange('currentSlide', (element: HTMLElement) => {
3022
let notes: string = undefined;
3123

3224
if (document && element) {
@@ -36,7 +28,7 @@ export class AppNotes {
3628
const md: Remarkable = new Remarkable({
3729
html: true,
3830
xhtmlOut: true,
39-
breaks: true
31+
breaks: true,
4032
});
4133

4234
const codeRule = (inline: boolean) => (tokens, idx, _options, _env) => {
@@ -63,8 +55,8 @@ export class AppNotes {
6355
}
6456

6557
componentDidUnload() {
66-
if (this.subscription) {
67-
this.subscription.unsubscribe();
58+
if (this.destroyListener) {
59+
this.destroyListener();
6860
}
6961
}
7062

remote/src/app/pages/app-remote/app-remote.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {Subscription} from 'rxjs';
55

66
import {isMobile} from '@deckdeckgo/utils';
77

8+
import notesStores from '../../stores/notes.store';
9+
810
// Types
911
import {
1012
DeckdeckgoEvent,
@@ -22,12 +24,11 @@ import {
2224

2325
// Utils
2426
import {ParseSlidesUtils} from '../../utils/parse-slides.utils';
27+
import {ParseAttributesUtils} from '../../utils/parse-attributes.utils';
2528

2629
// Services
2730
import {CommunicationService} from '../../services/communication/communication.service';
2831
import {AccelerometerService} from '../../services/accelerometer/accelerometer.service';
29-
import {NotesService} from '../../services/notes/notes.service';
30-
import {ParseAttributesUtils} from '../../utils/parse-attributes.utils';
3132

3233
@Component({
3334
tag: 'app-remote',
@@ -69,12 +70,10 @@ export class AppRemote {
6970

7071
private communicationService: CommunicationService;
7172
private accelerometerService: AccelerometerService;
72-
private notesService: NotesService;
7373

7474
constructor() {
7575
this.communicationService = CommunicationService.getInstance();
7676
this.accelerometerService = AccelerometerService.getInstance();
77-
this.notesService = NotesService.getInstance();
7877
}
7978

8079
componentWillLoad() {
@@ -297,7 +296,7 @@ export class AppRemote {
297296
next = this.el.querySelector('.deckgo-slide-container:nth-child(' + (this.slideIndex + 1) + ')');
298297
}
299298

300-
this.notesService.next(next);
299+
notesStores.state.currentSlide = next;
301300
}
302301

303302
private async lazyLoadPollContent($slideEvent: DeckdeckgoEventSlide) {

remote/src/app/services/notes/notes.service.tsx

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {createStore} from '@stencil/store';
2+
3+
interface NotesStore {
4+
currentSlide: HTMLElement | undefined;
5+
}
6+
7+
const {state, onChange} = createStore({
8+
currentSlide: undefined,
9+
} as NotesStore);
10+
11+
export default {state, onChange};

0 commit comments

Comments
 (0)