Options
All
  • Public
  • Public/Protected
  • All
Menu

Class LoadingItems

LoadingItems is the queue of items which can flow them into the loading pipeline.
Please don't construct it directly, use create instead, because we use an internal pool to recycle the queues.
It hold a map of items, each entry in the map is a url to object key value pair.
Each item always contains the following property:

  • id: The identification of the item, usually it's identical to url
  • url: The url
  • type: The type, it's the extension name of the url by default, could be specified manually too.
  • error: The error happened in pipeline will be stored in this property.
  • content: The content processed by the pipeline, the final result will also be stored in this property.
  • complete: The flag indicate whether the item is completed by the pipeline.
  • states: An object stores the states of each pipe the item go through, the state can be: Pipeline.ItemState.WORKING | Pipeline.ItemState.ERROR | Pipeline.ItemState.COMPLETE

    Item can hold other custom properties.
    Each LoadingItems object will be destroyed for recycle after onComplete callback
    So please don't hold its reference for later usage, you can copy properties in it though.

Hierarchy

  • CallbacksInvoker
    • LoadingItems

Index

Constructors

constructor

  • newLoadingItems(pipeline: any, urlList: any, onProgress: any, onComplete: any): LoadingItems

Properties

Private _appending

_appending: boolean = false

_callbackTable

_callbackTable: ICallbackTable = createMap(true)

Private _errorUrls

_errorUrls: Array<string> = []

Private _id

_id: number

_ownerQueue

_ownerQueue: LoadingItems | null = null

Private _pipeline

_pipeline: any

active

active: boolean

Activated or not.

completed

completed: {}

The map of completed items.

Type declaration

completedCount

completedCount: number = 0

Total count of completed items.

map

map: Map<string, IItem> = createMap(true)

The map of all items.

onComplete

onComplete: ((errors: string[] | null, items: LoadingItems) => void) | undefined

This is a callback which will be invoked while all items is completed, You can pass the callback function in LoadingItems.create or set it later.

param

All items.

param

All items.

example
import { log } from 'cc';
loadingItems.onComplete (errors, items) {
    if (error) {
        log('Completed with ' + errors.length + ' errors');
    } else {
        log('Completed ' + items.totalCount + ' items');
    }
}

onProgress

onProgress: ((completedCount: number, totalCount: number, IItem: any) => void) | undefined

This is a callback which will be invoked while an item flow out the pipeline. You can pass the callback function in LoadingItems.create or set it later.

param

The latest item which flow out the pipeline.

param

The latest item which flow out the pipeline.

param

The latest item which flow out the pipeline.

example
import { log } from 'cc';
loadingItems.onProgress (completedCount, totalCount, item) {
    let progress = (100 * completedCount / totalCount).toFixed(2);
    log(progress + '%');
}

totalCount

totalCount: number = 0

Total count of all items.

Static ItemState

ItemState: any = new legacyCC.Enum(ItemState)

The item states of the LoadingItems, its value could be {{ItemState.WORKING}} | {{ItemState.COMPLETE}} | {{ItemState.ERROR}}

Methods

childOnProgress

  • childOnProgress(item: any): void

addListener

  • addListener(key: string, callback: Function, target?: any): Function
  • Add a listener for an item, the callback will be invoked when the item is completed.

    Parameters

    • key: string

      The item key

    • callback: Function

      Callback function when item loaded

    • Optional target: any

      Callback callee

    Returns Function

allComplete

  • allComplete(): void

append

  • append(urlList: object[], owner?: any): IItem[]
  • Add urls to the LoadingItems queue.

    Parameters

    • urlList: object[]

      要追加的url列表,url可以是对象或字符串

    • Optional owner: any

    Returns IItem[]

    在已接受的url列表中,可以拒绝某些无效项

clear

  • clear(): void

destroy

  • destroy(): void

emit

  • emit(key: string, arg0?: any, arg1?: any, arg2?: any, arg3?: any, arg4?: any): void
  • Trigger an event directly with the event name and necessary arguments.

    Parameters

    • key: string

      event type

    • Optional arg0: any

      The first argument to be passed to the callback

    • Optional arg1: any

      The second argument to be passed to the callback

    • Optional arg2: any

      The third argument to be passed to the callback

    • Optional arg3: any

      The fourth argument to be passed to the callback

    • Optional arg4: any

      The fifth argument to be passed to the callback

    Returns void

exists

  • exists(id: string): boolean

getContent

  • getContent(id: string): any

getError

  • getError(id: string): any

hasEventListener

  • hasEventListener(key: string, callback?: Function, target?: Object): boolean
  • Checks whether there is correspond event listener registered on the given event

    Parameters

    • key: string

      Event type

    • Optional callback: Function

      Callback function when event triggered

    • Optional target: Object

      Callback callee

    Returns boolean

hasListener

  • hasListener(key: string, callback?: Function, target?: any): boolean
  • Check if the specified key has any registered callback. If a callback is also specified, it will only return true if the callback is registered.

    Parameters

    • key: string

      The item key

    • Optional callback: Function

      Callback function when item loaded

    • Optional target: any

      Callback callee

    Returns boolean

    Whether the corresponding listener for the item is registered

isCompleted

  • isCompleted(): boolean

isItemCompleted

  • isItemCompleted(id: string): boolean

itemComplete

  • itemComplete(id: string): void

off

  • off(key: string, callback?: Function, target?: Object): void
  • Remove event listeners registered with the given event key, callback and target

    Parameters

    • key: string

      Event type

    • Optional callback: Function

      The callback function of the event listener, if absent all event listeners for the given type will be removed

    • Optional target: Object

      The callback callee of the event listener

    Returns void

on

  • on(key: string, callback: Function, target?: Object, once?: undefined | false | true): Function
  • Register an event listener to a given event key with callback and target.

    Parameters

    • key: string

      Event type

    • callback: Function

      Callback function when event triggered

    • Optional target: Object

      Callback callee

    • Optional once: undefined | false | true

      Whether invoke the callback only once (and remove it)

    Returns Function

removeAll

  • removeAll(keyOrTarget: string | Object): void
  • Removes all callbacks registered in a certain event type or all callbacks registered with a certain target

    Parameters

    • keyOrTarget: string | Object

      The event type or target with which the listeners will be removed

    Returns void

removeAllListeners

  • removeAllListeners(key: any): void
  • Removes all callbacks registered in a certain event type or all callbacks registered with a certain target.

    Parameters

    • key: any

      The item key to be removed or the target to be removed

    Returns void

removeItem

  • removeItem(url: string): void

removeListener

  • removeListener(key: string, callback?: Function, target?: any): void
  • Removes a listener. It will only remove when key, callback, target all match correctly.

    Parameters

    • key: string

      The item key

    • Optional callback: Function

      Callback function when item loaded

    • Optional target: any

      Callback callee

    Returns void

Static create

  • create(pipeline: any, urlList: any, onProgress?: any, onComplete?: any): LoadingItems
  • The constructor function of LoadingItems, this will use recycled LoadingItems in the internal pool if possible. You can pass onProgress and onComplete callbacks to visualize the loading process.

    example
    import { log, LoadingItems } from 'cc';
    LoadingItems.create(loader, ['a.png', 'b.plist'], function (completedCount, totalCount, item) {
        let progress = (100 * completedCount / totalCount).toFixed(2);
        log(progress + '%');
    }, function (errors, items) {
        if (errors) {
            for (let i = 0; i < errors.length; ++i) {
                log('Error url: ' + errors[i] + ', error: ' + items.getError(errors[i]));
            }
        }
        else {
            let result_a = items.getContent('a.png');
            // ...
        }
    })

    Parameters

    • pipeline: any

      The pipeline to process the queue.

    • urlList: any

      The items array.

    • Optional onProgress: any
    • Optional onComplete: any

    Returns LoadingItems

    The LoadingItems queue object

Static finishDep

  • finishDep(depId: any): void

Static getQueue

Static initQueueDeps

  • initQueueDeps(queue: any): void

Static itemComplete

  • itemComplete(item: IItem): void

Static registerQueueDep

  • registerQueueDep(owner: any, depId: any): undefined | false

Generated using TypeDoc