Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Pipeline

A pipeline describes a sequence of manipulations, each manipulation is called a pipe.
It's designed for loading process. so items should be urls, and the url will be the identity of each item during the process.
A list of items can flow in the pipeline and it will output the results of all pipes.
They flow in the pipeline like water in tubes, they go through pipe by pipe separately.
Finally all items will flow out the pipeline and the process is finished.

Hierarchy

Index

Constructors

constructor

  • en

    The constructor of the Pipeline, the order of pipes will remain as given. A pipe is an {{IPipe}} object which must have an id and a handle function, the id must be unique. It should also include an async property to identify whether the pipe's handle function is asynchronous.

    zh

    构造函数,通过一系列的 pipe 来构造一个新的 pipeline,pipes 将会在给定的顺序中被锁定。
    一个 pipe 就是一个对象,它包含了字符串类型的 ‘id’ 和 ‘handle’ 函数,在 pipeline 中 id 必须是唯一的。
    它还可以包括 ‘async’ 属性以确定它是否是一个异步过程。

    example
     let pipeline = new Pipeline([
         {
             id: 'Downloader',
             handle: function (item, callback) {},
             async: true
         },
         {id: 'Parser', handle: function (item) {}, async: false}
     ]);

    Parameters

    • pipes: IPipe[]

      All pipes for constructing the pipeline

    Returns Pipeline

Properties

_cache

_cache: any = createMap(true)

Protected _pipes

_pipes: Array<IPipe>

Static ItemState

ItemState: any = ItemState

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

Methods

appendPipe

  • appendPipe(pipe: IPipe): void
  • Add a new pipe at the end of the pipeline.
    A pipe must contain an id in string and a handle function, the id must be unique in the pipeline.

    Parameters

    • pipe: IPipe

      The pipe to be appended

    Returns void

clear

  • clear(): void

copyItemStates

  • Copy the item states from one source item to all destination items.
    It's quite useful when a pipe generate new items from one source item,
    then you should flowIn these generated items into pipeline,
    but you probably want them to skip all pipes the source item already go through,
    you can achieve it with this API.

    For example, an unzip pipe will generate more items, but you won't want them to pass unzip or download pipe again.

    Parameters

    • srcItem: IItem

      The source item

    • dstItems: IItem | Array<IItem>

      A single destination item or an array of destination items

    Returns void

flowIn

  • flowIn(items: Array<IItem>): void
  • Let new items flow into the pipeline.
    Each item can be a simple url string or an object, if it's an object, it must contain id property.
    You can specify its type by type property, by default, the type is the extension name in url.
    By adding a skips property including pipe ids, you can skip these pipe.
    The object can contain any supplementary property as you want.

    example
     pipeline.flowIn([
         'res/Background.png',
         {
             id: 'res/scene.json',
             type: 'scene',
             name: 'scene',
             skips: ['Downloader']
         }
     ]);

    Parameters

    • items: Array<IItem>

      The {{IItem}} to be appended to the current pipeline

    Returns void

flowInDeps

  • flowInDeps(owner: IItem, urlList: object[], callback: Function): IItem[]
  • Let new items flow into the pipeline and give a callback when the list of items are all completed.
    This is for loading dependencies for an existing item in flow, usually used in a pipe logic.
    For example, we have a loader for scene configuration file in JSON, the scene will only be fully loaded
    after all its dependencies are loaded, then you will need to use function to flow in all dependencies
    found in the configuration file, and finish the loader pipe only after all dependencies are loaded (in the callback).

    Parameters

    • owner: IItem

      The owner item

    • urlList: object[]

      The list of urls to be appended as dependencies of the owner.

    • callback: Function

      The callback to be invoked when all dependencies are completed.

    Returns IItem[]

    Items accepted by the pipeline

flowOut

  • flowOut(item: IItem): void

getItem

  • getItem(id: string): IItem | null

insertPipe

  • insertPipe(pipe: IPipe, index: number): void
  • Insert a new pipe at the given index of the pipeline.
    A pipe must contain an id in string and a handle function, the id must be unique in the pipeline.

    Parameters

    • pipe: IPipe

      The pipe to be inserted

    • index: number

      The index to insert

    Returns void

insertPipeAfter

  • insertPipeAfter(refPipe: IPipe, newPipe: IPipe): void
  • Insert a pipe to the end of an existing pipe. The existing pipe must be a valid pipe in the pipeline.

    Parameters

    • refPipe: IPipe

      An existing pipe in the pipeline.

    • newPipe: IPipe

      The pipe to be inserted.

    Returns void

removeItem

  • removeItem(id: string): boolean
  • Removes an completed item in pipeline. It will only remove the cache in the pipeline or loader, its dependencies won't be released. loader provided another method to completely cleanup the resource and its dependencies, please refer to {{Loader.release}}

    Parameters

    • id: string

      The id of the item

    Returns boolean

    succeed or not

Generated using TypeDoc