mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
refactor(server/notes): Implement singleton architecture
Also trying something out with the response structure on the server to cut down on redundant calls.
This commit is contained in:
1 parent
d93bdd20d8
commit
0bb20fff31
8 files changed
+219
-136
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { NotesEvents } from '../../typings/notes';
|
||||
import { Note, NoteServerResponse, NotesEvents } from '../../typings/notes';
|
||||
import { sendNotesEvent } from '../utils/messages';
|
||||
|
||||
onNet(NotesEvents.SEND_NOTE, (notes: any) => {
|
||||
@@ -6,34 +6,36 @@ onNet(NotesEvents.SEND_NOTE, (notes: any) => {
|
||||
});
|
||||
|
||||
RegisterNuiCallbackType(NotesEvents.ADD_NOTE);
|
||||
on(`__cfx_nui:${NotesEvents.ADD_NOTE}`, (data: any) => {
|
||||
emitNet(NotesEvents.ADD_NOTE, data);
|
||||
});
|
||||
|
||||
onNet(NotesEvents.SEND_NOTE_SUCCESS, () => {
|
||||
emitNet(NotesEvents.FETCH_ALL_NOTES);
|
||||
});
|
||||
|
||||
onNet(NotesEvents.DELETE_NOTE_SUCCESS, () => {
|
||||
emitNet(NotesEvents.FETCH_ALL_NOTES);
|
||||
on(`__cfx_nui:${NotesEvents.ADD_NOTE}`, (note: Note) => {
|
||||
emitNet(NotesEvents.ADD_NOTE, note);
|
||||
});
|
||||
|
||||
RegisterNuiCallbackType(NotesEvents.DELETE_NOTE);
|
||||
on(`__cfx_nui:${NotesEvents.DELETE_NOTE}`, (data: any) => {
|
||||
emitNet(NotesEvents.DELETE_NOTE, data);
|
||||
|
||||
emitNet(NotesEvents.FETCH_ALL_NOTES);
|
||||
on(`__cfx_nui:${NotesEvents.DELETE_NOTE}`, (noteId: number) => {
|
||||
emitNet(NotesEvents.DELETE_NOTE, noteId);
|
||||
});
|
||||
|
||||
RegisterNuiCallbackType(NotesEvents.UPDATE_NOTE);
|
||||
on(`__cfx_nui:${NotesEvents.UPDATE_NOTE}`, (data: any) => {
|
||||
emitNet(NotesEvents.UPDATE_NOTE, data);
|
||||
on(`__cfx_nui:${NotesEvents.UPDATE_NOTE}`, (note: Note) => {
|
||||
emitNet(NotesEvents.UPDATE_NOTE, note);
|
||||
});
|
||||
|
||||
onNet(NotesEvents.UPDATE_NOTE_SUCCESS, () => {
|
||||
emitNet(NotesEvents.FETCH_ALL_NOTES);
|
||||
});
|
||||
// Trying out this response structure
|
||||
onNet(
|
||||
NotesEvents.SERVER_RESP,
|
||||
({ alert, action, suceeded, refetch, data }: NoteServerResponse<Note[] | Note>) => {
|
||||
if (alert) {
|
||||
sendNotesEvent(NotesEvents.SEND_ALERT, alert);
|
||||
}
|
||||
|
||||
onNet(NotesEvents.ACTION_RESULT, (alert: any) => {
|
||||
sendNotesEvent(NotesEvents.SEND_ALERT, alert);
|
||||
});
|
||||
switch (action) {
|
||||
case 'SEND':
|
||||
sendNotesEvent(NotesEvents.SEND_NOTE, data);
|
||||
break;
|
||||
}
|
||||
|
||||
if (refetch && suceeded) {
|
||||
emitNet(NotesEvents.FETCH_ALL_NOTES);
|
||||
}
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user