WordPress.org

Make WordPress Core

Changeset 25078


Ignore:
Timestamp:
08/21/2013 10:54:09 PM (8 years ago)
Author:
azaozz
Message:

Heartbeat: better queue functionality: improve enqueue() and isQueued(), introduce dequeue() and getQueuedItem(). Props evansolomon, fixes #25047.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/heartbeat.js

    r24908 r25078  
    428428        this.enqueue = function( handle, data, dont_overwrite ) {
    429429            if ( handle ) {
    430                 if ( queue.hasOwnProperty( handle ) && dont_overwrite )
     430                if ( dont_overwrite && this.isQueued( handle ) )
    431431                    return false;
    432432
     
    441441         *
    442442         * $param string handle The handle for the data
    443          * $return mixed The data queued with that handle or null
     443         * $return bool Whether some data is queued with this handle
    444444         */
    445445        this.isQueued = function( handle ) {
    446             return queue[handle];
     446            if ( handle )
     447                return queue.hasOwnProperty( handle );
     448        };
     449
     450        /**
     451         * Remove data with a particular handle from the queue
     452         *
     453         * $param string handle The handle for the data
     454         * $return void
     455         */
     456        this.dequeue = function( handle ) {
     457            if ( handle )
     458                delete queue[handle];
     459        };
     460
     461        /**
     462         * Get data that was enqueued with a particular handle
     463         *
     464         * $param string handle The handle for the data
     465         * $return mixed The data or undefined
     466         */
     467        this.getQueuedItem = function( handle ) {
     468            if ( handle )
     469                return this.isQueued( handle ) ? queue[handle] : undefined;
    447470        };
    448471    };
Note: See TracChangeset for help on using the changeset viewer.