ES6 in iOS 12

곰튀김·2022년 4월 8일
0

iOS 12 에서 Promise.allSettled 가 동작하지 않아서 서비스 장애가 발생했다.
compatibility 를 확인하지 않았던 것이 문제다.

그렇다면 이것을 하나하나 Polyfill 해야 하나?

if (!('allSettled' in Promise)) {
  // @ts-ignore
  Promise['allSettled'] = function <T>(promises: Promise<T>[]) {
    const mappedPromises = promises.map((p) => {
      return p
        .then((value) => {
          return {
            status: 'fulfilled',
            value,
          };
        })
        .catch((reason) => {
          return {
            status: 'rejected',
            reason,
          };
        });
    });
    return Promise.all(mappedPromises);
  };
}

이미 누군가 만들어 놓은 것이 있을 것이다!! 찾아보면... 꽤 있네..
그 중에 polyfill-advance으로 픽함.

index.tsx 에서 이 한 줄 넣어주면 끝난다.

import 'polyfill-advance';

세상 좋아졌네.

profile
사실주의 프로그래머

1개의 댓글

comment-user-thumbnail
2022년 4월 8일

https://github.com/zloirock/core-js
이것도 생각했는데.. 과하다!

답글 달기