Skip to content
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

[issues : error] fetch 이후 addEventListener 에러 #46

Open
77unny opened this issue Mar 17, 2020 · 3 comments
Open

[issues : error] fetch 이후 addEventListener 에러 #46

77unny opened this issue Mar 17, 2020 · 3 comments

Comments

@77unny
Copy link
Collaborator

77unny commented Mar 17, 2020

'addEventListener' of null ...
컨트롤러에 init() 메소드에 async, getInitialData()에 await 처리
각 모델의 getInitialData 메소드는 promise 로 감싼다

controller.js

async init() {
    // register observers
    this.itemPanelView.registerAsObserver();
    this.statePanelView.registerAsObserver();
    this.walletView.registerAsObserver();

    // fetch data & render UI
    await this.vendingMachineModel.getInitialData();
    await this.walletModel.getInitialData();

vendingMachineModel.js

getInitialData() {
    return new Promise(res => {
      res(
        this.http.get(this.url).then(data => {
          this.menu = data;
          localStorage.setItem("menuDB", JSON.stringify(this.menu));
          this.notify("onLoad", this.menu);
        })
      );
    });
  }
@reesekimm
Copy link
Collaborator

reesekimm commented Mar 17, 2020

@baekCode
어제 배운 거 바로 활용하셨네요~! 👍
아쉬운 부분은 http 모듈을 만든 의미가 조금 퇴색되었다는 점..ㅎ
http 모듈에 async/await/promise를 모아두고 서비스 로직에서 분리함으로써 가독성을 높이는 효과도 있었는데 다시 등장한 셈..ㅠ

@77unny
Copy link
Collaborator Author

77unny commented Mar 17, 2020

@reesekimm
ㅠㅠ 그게 조금 맘에 걸리긴했어요 ㅠㅠ 다른 방법이 있을까용?

@reesekimm
Copy link
Collaborator

reesekimm commented Mar 17, 2020

@baekCode
크롱이 힌트 주신 event delegation으로 해결해보면 어떨까용? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants