How to use the core-js/library/es6/promise function in core-js

To help you get started, we’ve selected a few core-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nhn / tui.image-editor / src / js / component / imageLoader.js View on Github external
load(imageName, img) {
        let promise;

        if (!imageName && !img) { // Back to the initial state, not error.
            const canvas = this.getCanvas();

            canvas.backgroundImage = null;
            canvas.renderAll();

            promise = new Promise(resolve => {
                this.setCanvasImage('', null);
                resolve();
            });
        } else {
            promise = this._setBackgroundImage(img).then(oImage => {
                this.setCanvasImage(imageName, oImage);
                this.adjustCanvasDimension();

                return oImage;
            });
        }

        return promise;
    }
github nhn / tui.image-editor / test / imageEditor.spec.js View on Github external
it('removeObjectStream () must be executed as many times as the length of the Object array.', done => {
            const promise = new Promise(resolve => {
                resolve();
            });

            spyOn(imageEditor, '_removeObjectStream').and.callThrough();
            spyOn(imageEditor, 'removeObject').and.returnValue(promise);

            const removeJobsSequens = [1, 2, 3, 4];
            const expected = removeJobsSequens.length + 1;
            const removeObjectStremPromise = imageEditor._removeObjectStream(removeJobsSequens);

            removeObjectStremPromise.then(() => {
                expect(imageEditor._removeObjectStream.calls.count()).toBe(expected);
                done();
            });
        });
github nhn / tui.image-editor / test / action.spec.js View on Github external
it('add once event mousedown should be executed When the addIcon action occurs', () => {
            const promise = new Promise(resolve => {
                resolve(300);
            });

            spyOn(imageEditorMock, 'changeCursor');
            spyOn(imageEditorMock, 'addIcon').and.returnValue(promise);

            iconAction.addIcon('iconTypeA');
            expect(imageEditorMock.changeCursor).toHaveBeenCalled();

            imageEditorMock.fire('mousedown', null, {
                x: 10,
                y: 10
            });
            expected = imageEditorMock.addIcon.calls.mostRecent().args[0];
            expect(expected).toBe('iconTypeA');
        });
github nhn / tui.image-editor / src / js / component / filter.js View on Github external
add(type, options) {
        return new Promise((resolve, reject) => {
            const sourceImg = this._getSourceImage();
            const canvas = this.getCanvas();
            let imgFilter = this._getFilter(sourceImg, type);
            if (!imgFilter) {
                imgFilter = this._createFilter(sourceImg, type, options);
            }

            if (!imgFilter) {
                reject(rejectMessages.invalidParameters);
            }

            this._changeFilterValues(imgFilter, options);

            this._apply(sourceImg, () => {
                canvas.renderAll();
                resolve({
github nhn / tui.image-editor / src / js / component / shape.js View on Github external
add(type, options) {
        return new Promise(resolve => {
            const canvas = this.getCanvas();
            options = this._extendOptions(options);
            const shapeObj = this._createInstance(type, options);

            this._bindEventOnShape(shapeObj);

            canvas.add(shapeObj).setActiveObject(shapeObj);

            const objectProperties = this.graphics.createObjectProperties(shapeObj);

            resolve(objectProperties);
        });
    }
github nhn / tui.image-editor / src / js / component / shape.js View on Github external
change(shapeObj, options) {
        return new Promise((resolve, reject) => {
            if (inArray(shapeObj.get('type'), shapeType) < 0) {
                reject(rejectMessages.unsupportedType);
            }

            shapeObj.set(options);
            this.getCanvas().renderAll();
            resolve();
        });
    }
github nhn / tui.image-editor / src / js / component / text.js View on Github external
setStyle(activeObj, styleObj) {
        return new Promise(resolve => {
            snippet.forEach(styleObj, (val, key) => {
                if (activeObj[key] === val) {
                    styleObj[key] = resetStyles[key] || '';
                }
            }, this);

            activeObj.set(styleObj);

            this.getCanvas().renderAll();
            resolve();
        });
    }
github nhn / tui.image-editor / src / js / component / main.js View on Github external
addImageObject(imgUrl) {
        const callback = bind(this._callbackAfterLoadingImageObject, this);

        return new Promise(resolve => {
            fabric.Image.fromURL(imgUrl, image => {
                callback(image);
                resolve();
            }, {
                crossOrigin: 'Anonymous'
            }
            );
        });
    }
github nhn / tui.image-editor / src / js / component / imageLoader.js View on Github external
_setBackgroundImage(img) {
        if (!img) {
            return Promise.reject(rejectMessages.loadImage);
        }

        return new Promise((resolve, reject) => {
            const canvas = this.getCanvas();

            canvas.setBackgroundImage(img, () => {
                const oImage = canvas.backgroundImage;

                if (oImage && oImage.getElement()) {
                    resolve(oImage);
                } else {
                    reject(rejectMessages.loadingImageFailed);
                }
            }, imageOption);
        });
    }
}