function update() {
        // Caching this.malakh.[a-zA-Z]* instances.
        // Note: we avoid using ES5 getters here for performance reasons.
        var malakh = that.malakh,
            $container = malakh.$container,
            $canvas = malakh.$canvas,
            viewport = malakh.viewport,
            tiledImages = malakh.tiledImages,
            drawer = malakh.drawer;

        var containerCss = $container.css(['width', 'height']);
        var newContainerSize = new Malakh.Point(parseFloat(containerCss.width), parseFloat(containerCss.height));

        if (!newContainerSize.equals(containerSize)) {
            // Maintain image position:
            forceRedraw = true; // canvas needs it
            containerSize = newContainerSize; // TODO maybe keep it as a Malakh parameter?
            viewport.resize(newContainerSize);

            // Resize canvas.
            $canvas
                .attr('width', newContainerSize.x)
                .attr('height', newContainerSize.y);

            // Let the world know we resized.
            $container.trigger('malakh:resize');
        }

        // animating => viewport moved, aligning images or loading/blending tiles.
        var animating = viewport.update() || forceAlign || forceRedraw;
        if (forceAlign) {
            forceAlign = false;
            setTimeout(function () { // Making it more asynchronous.
                utils.forEach(tiledImages, function (tiledImage, whichImage) {
                    if (tiledImage instanceof Malakh.TiledImage) { // tiled image has been loaded
                        scheduleUpdateTiledImageBounds(whichImage);
                    }
                });
            });
        }

        if (animating) {
            forceRedraw = drawer.update();
        } else {
            lockOnUpdates = true;
        }

        // Triger proper events.
        if (!animated && animating) {
            // We weren't animating, and now we did ==> animation start.
            $container
                .trigger('malakh:animation_start')
                .trigger('malakh:animation');
        } else if (animating) {
            // We're in the middle of animating.
            $container.trigger('malakh:animation');
        } else if (animated) {
            // We were animating, and now we're not anymore ==> animation finish.
            $container.trigger('malakh:animation_end');
        }

        // For the next update check.
        animated = animating;

        scheduleUpdate();
    }
/**
     * A single update process, delegating drawing to the Drawer on a change.
     * @private
     */
A single update process, delegating drawing to the Drawer on a change.
@private
A single update process delegating drawing to the Drawer on a change . @private
function update() {
        var malakh = that.malakh,
            $container = malakh.$container,
            $canvas = malakh.$canvas,
            viewport = malakh.viewport,
            tiledImages = malakh.tiledImages,
            drawer = malakh.drawer;
        var containerCss = $container.css(['width', 'height']);
        var newContainerSize = new Malakh.Point(parseFloat(containerCss.width), parseFloat(containerCss.height));
        if (!newContainerSize.equals(containerSize)) {
            forceRedraw = true; 
            containerSize = newContainerSize; 
            viewport.resize(newContainerSize);
            $canvas
                .attr('width', newContainerSize.x)
                .attr('height', newContainerSize.y);
            $container.trigger('malakh:resize');
        }
        var animating = viewport.update() || forceAlign || forceRedraw;
        if (forceAlign) {
            forceAlign = false;
            setTimeout(function () { 
                utils.forEach(tiledImages, function (tiledImage, whichImage) {
                    if (tiledImage instanceof Malakh.TiledImage) { 
                        scheduleUpdateTiledImageBounds(whichImage);
                    }
                });
            });
        }
        if (animating) {
            forceRedraw = drawer.update();
        } else {
            lockOnUpdates = true;
        }
        if (!animated && animating) {
            $container
                .trigger('malakh:animation_start')
                .trigger('malakh:animation');
        } else if (animating) {
            $container.trigger('malakh:animation');
        } else if (animated) {
            $container.trigger('malakh:animation_end');
        }
        animated = animating;
        scheduleUpdate();
    }
function update ( ) { var malakh = that . malakh , $container = malakh . $container , $canvas = malakh . $canvas , viewport = malakh . viewport , tiledImages = malakh . tiledImages , drawer = malakh . drawer ; var containerCss = $container . css ( [ 'width' , 'height' ] ) ; var newContainerSize = new Malakh . Point ( parseFloat ( containerCss . width ) , parseFloat ( containerCss . height ) ) ; if ( ! newContainerSize . equals ( containerSize ) ) { forceRedraw = true ; containerSize = newContainerSize ; viewport . resize ( newContainerSize ) ; $canvas . attr ( 'width' , newContainerSize . x ) . attr ( 'height' , newContainerSize . y ) ; $container . trigger ( 'malakh:resize' ) ; } var animating = viewport . update ( ) || forceAlign || forceRedraw ; if ( forceAlign ) { forceAlign = false ; setTimeout ( function ( ) { utils . forEach ( tiledImages , function ( tiledImage , whichImage ) { if ( tiledImage instanceof Malakh . TiledImage ) { scheduleUpdateTiledImageBounds ( whichImage ) ; } } ) ; } ) ; } if ( animating ) { forceRedraw = drawer . update ( ) ; } else { lockOnUpdates = true ; } if ( ! animated && animating ) { $container . trigger ( 'malakh:animation_start' ) . trigger ( 'malakh:animation' ) ; } else if ( animating ) { $container . trigger ( 'malakh:animation' ) ; } else if ( animated ) { $container . trigger ( 'malakh:animation_end' ) ; } animated = animating ; scheduleUpdate ( ) ; }
A single update process, delegating drawing to the Drawer on a change.
A single update process delegating drawing to the Drawer on a change .
// Caching this.malakh.[a-zA-Z]* instances. // Note: we avoid using ES5 getters here for performance reasons. // Maintain image position: // canvas needs it // TODO maybe keep it as a Malakh parameter? // Resize canvas. // Let the world know we resized. // animating => viewport moved, aligning images or loading/blending tiles. // Making it more asynchronous. // tiled image has been loaded // Triger proper events. // We weren't animating, and now we did ==> animation start. // We're in the middle of animating. // We were animating, and now we're not anymore ==> animation finish. // For the next update check.