mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
Feat/inject debug - Use new abstraction to clean up debug data (#70)
* feat(phone/debug): Inject debug data for development * refactor(phone/debug): Refactored mock data to InjectDebugEvents * fix(phone/debug) removed useless debug injections
This commit is contained in:
11 files changed
+243
-256
No files matched your search
@@ -0,0 +1,48 @@
|
||||
interface DebugEvent {
|
||||
app: string;
|
||||
method: string;
|
||||
data: any;
|
||||
}
|
||||
|
||||
// TODO: This should be unit tested
|
||||
|
||||
/**
|
||||
* Will mock data as if it were coming from an NUI message event
|
||||
* @param events {DebugEvent[]} An array of debug events
|
||||
* @example
|
||||
* InjectDebugData([
|
||||
* {
|
||||
* app: 'CAMERA',
|
||||
* method: 'setPhotos',
|
||||
* data: [
|
||||
* {
|
||||
* id: 1,
|
||||
* image: 'https://i.imgur.com/OO8wx6Z.jpg',
|
||||
* },
|
||||
* {
|
||||
* id: 2,
|
||||
* image: 'https://i.imgur.com/OO8wx6Z.jpg',
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
* ])
|
||||
**/
|
||||
const InjectDebugData = (events: DebugEvent[]) => {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
for (const event of events) {
|
||||
setTimeout(() => {
|
||||
window.dispatchEvent(
|
||||
new MessageEvent('message', {
|
||||
data: {
|
||||
app: event.app,
|
||||
method: event.method,
|
||||
data: event.data,
|
||||
},
|
||||
})
|
||||
);
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default InjectDebugData;
|
||||
Reference in new issue
Block a user