๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
ionic

๐ŸฅIonic์—์„œ redux dev tools ์‚ฌ์šฉํ•ด๋ณด๊ธฐ

by frontChoi 2021. 11. 27.
๋ฐ˜์‘ํ˜•

๐Ÿง‘ Ionic + Angular +Ngrx

ํ˜„ ํšŒ์‚ฌ์—์„œ Ionic ์ƒํƒœ๊ด€๋ฆฌ๊ฐ€ ๋˜์–ด์žˆ์ง€ ์•Š์•˜๋‹ค. ๊ทธ๋ฆฌํ•˜์—ฌ Ionic์ด Anuglar์— ๋Œ€ํ•œ ์ž๋ฃŒ๊ฐ€ ๋งŽ์•„์„œ Angular๋Š” ์ƒํƒœ๊ด€๋ฆฌ๋Š” ์–ด๋–ป๊ฒŒ ํ•˜๋Š”๊ฐ€๋ฅผ ์ฐพ์•„๋ณด๋‹ค, Ngrx๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์—ˆ๋‹ค. ํ•˜์ง€๋งŒ ๋ฌด์Šจ์ด์œ ์ธ์ง€ ํฌ๋กฌ ํ™•์žฅ์ž redux-dev-tools์—์„œ ์•„๋ฌด๊ฒƒ๋„ ๋ณด์ด์ง€ ์•Š๋Š”๋‹ค... ๊ทธ๋ž˜์„œ ์ƒˆ๋กœ์šด ๋ฐฉ๋ฒ•์„ ์ฐพ์•„๋ณด์•˜๋‹ค.

 

๐Ÿถ ionic-remote-devtool ์†Œ์Šค๋ฅผ ๋ฐ›์ž!

https://github.com/somq/ionic4-remote-devtool ์—์„œ git clone ํ•˜์—ฌ ์†Œ์Šค๋ฅผ ๋ฐ›์ž

 

git clone https://github.com/somq/remotedev-server.git

 

๋‹ค์Œ์œผ๋กœ npm intall๋ฅผ ํ•ด์ฃผ์ž

๐Ÿ˜Š Ionic ํ”„๋กœ์ ํŠธ์— remotedev๋ฅผ ์„ค์น˜ํ•ด์ฃผ์ž

npm install --save-dev remotedev

์œ„ ์„ค์น˜๋ฅผ ํ†ตํ•˜์—ฌ ionic4-remote-devtool ๊ณผ ์—ฐ๊ฒฐํ•˜์—ฌ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

 

 

๐Ÿ˜‡ remote-devtools-connection-proxy.ts, remote-devtools-proxy.ts ์ƒ์„ฑ

ionic ํ”„๋กœ์ ํŠธ app ํด๋” ๋ฐ‘์— "remote-devtools-connection-proxy.ts,remote-devtools-proxy.ts"๋ฅผ ๋งŒ๋“ค์–ด์ฃผ์ž

 

remote-devtools-connection-proxy.ts

import { ReduxDevtoolsExtensionConnection } from '@ngrx/store-devtools/src/extension';

export class RemoteDevToolsConnectionProxy
  implements ReduxDevtoolsExtensionConnection {
  constructor(public remotedev: any, public instanceId: string) {}
    init(state?: any): void {
        //throw new Error('Method not implemented.');
    }
    error(anyErr: any): void {
        //throw new Error('Method not implemented.');
    }

  subscribe(listener: (change: any) => void): any {
    const listenerWrapper = (change: any) => {
      listener(change);
    };

    this.remotedev.subscribe(listenerWrapper);
    // Hack fix for commit/time-travelling etc. if the devtools are already open
    setTimeout(() => listenerWrapper({ type: 'START' }));
  }

  unsubscribe(): any {
    // HACK fix bug in @ngrx/store-devtools that calls this instead of returning
    // a lambda that calls it when their Observable wrapper is unsubscribed.
    return () => this.remotedev.unsubscribe(this.instanceId);
  }

  send(action: any, state: any): any {
    // Never called
  }
}

remote-devtools-proxy.ts

import { ReduxDevtoolsExtension, ReduxDevtoolsExtensionConnection, ReduxDevtoolsExtensionConfig } from '@ngrx/store-devtools/src/extension';
import { RemoteDevToolsConnectionProxy } from './remote-devtools-connection-proxy'
import { connect } from 'remotedev/lib/devTools';

export class RemoteDevToolsProxy implements ReduxDevtoolsExtension {
    remotedev: any = null;
    defaultOptions = {
        realtime: true,
        // Needs to match what you run `remotedev` command with and 
        // what you setup in remote devtools local connection settings
        hostname: 'localhost',
        port: 8000,
        autoReconnect: true,
        connectTimeout: 20000,
        ackTimeout: 10000,
        secure: true
    };

    constructor(defaultOptions: Object) {
        this.defaultOptions = Object.assign(this.defaultOptions, defaultOptions);
    }
    

    connect(options: ReduxDevtoolsExtensionConfig): ReduxDevtoolsExtensionConnection {
      const connectOptions = Object.assign(this.defaultOptions, options);
      this.remotedev = connect(connectOptions);

      const connectionProxy = new RemoteDevToolsConnectionProxy(
        this.remotedev,
        connectOptions.name
      );
      return connectionProxy;
    }
    
    send(action: any, state: any): any{
        this.remotedev.send(action,state);
    }
}

 

 

 

๐Ÿ˜› remote ํŒŒ์ผ์„ app.moudule์— ์ถ”๊ฐ€ํ•ด์ฃผ์ž!

 

app.module.ts

import { RemoteDevToolsProxy } from './remote-devtools-proxy';


if (!window['devToolsExtension'] && !window['__REDUX_DEVTOOLS_EXTENSION__']) {
  let remoteDevToolsProxy = new RemoteDevToolsProxy({
    connectTimeout: 300000, // extend for pauses during debugging
    ackTimeout: 120000, // extend for pauses during debugging
    secure: false // dev only
  });

  window['devToolsExtension'] = remoteDevToolsProxy;
  window['__REDUX_DEVTOOLS_EXTENSION__'] = remoteDevToolsProxy;
}
.
.
.
.
.
export class AppModule {}

 

๐Ÿคก remote-dev-tools๋ฅผ ์‹คํ–‰์‹œํ‚ค์ž

remotedev --hostname=localhost --port=8000

๊ทธ๋Ÿฌ๋ฉด ๋ธŒ๋ผ์šฐ์ €์—์„œ localhost:8000๋ฅผ ๋„์–ด๋ณธ๋‹ค.

์•„๋ž˜์™€  ๊ฐ™์ด ๋œจ๋Š”๊ฑธ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

 

๐Ÿ›บ ๊ฐœ๋ฐœ์ž ๋„๊ตฌ์—์„œ ํฌํŠธํฌ์›Œ๋”ฉ์„ ์‹œํ‚ค์ž

์•„๋ž˜ ์‚ฌ์ง„์ฒ˜๋Ÿผ ํฌํŠธํฌ์›Œ๋”ฉ์„ ํ†ตํ•ด์„œ localhost:8000์„ ํ•ด์ฃผ๋ฉด ionic+angular์—์„œ redux-dev-tools์ด ์‚ฌ์šฉ๊ฐ€๋Šฅํ•˜๋‹ค.

๋ฐ˜์‘ํ˜•

'ionic' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

๐Ÿค ionic fcm background์—์„œ ๋ฐ์ดํ„ฐ ๋ฐ›๊ธฐ  (1) 2022.03.20
Ionic Speech Recognition  (0) 2022.01.01
๐ŸŒŠIonic Android APK ์ถ”์ถœ  (0) 2021.10.01
๐Ÿณโ€๐ŸŒˆProxy ์„ธํŒ…  (0) 2021.09.07
ionic + angular ์„ธํŒ…  (2) 2021.07.31

๋Œ“๊ธ€