All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.cesium.Request.kt Maven / Gradle / Ivy

// Automatically generated - do not modify!

@file:JsModule("cesium")

@file:Suppress(
    "NON_EXTERNAL_DECLARATION_IN_INAPPROPRIATE_FILE",
)

package cesium

/**
 * Stores information for making a request. In general this does not need to be constructed directly.
 * @see Online Documentation
 */
external class Request(options: ConstructorOptions? = definedExternally) {
    /**
     * @property [url] The url to request.
     * @property [requestFunction] The function that makes the actual data request.
     * @property [cancelFunction] The function that is called when the request is cancelled.
     * @property [priorityFunction] The function that is called to update the request's priority, which occurs once per frame.
     * @property [priority] The initial priority of the request.
     *   Default value - `0.0`
     * @property [throttle] Whether to throttle and prioritize the request. If false, the request will be sent immediately. If true, the request will be throttled and sent based on priority.
     *   Default value - `false`
     * @property [throttleByServer] Whether to throttle the request by server.
     *   Default value - `false`
     * @property [type] The type of request.
     *   Default value - [RequestType.OTHER]
     */
    interface ConstructorOptions {
        var url: String?
        var requestFunction: RequestCallback?
        var cancelFunction: CancelCallback?
        var priorityFunction: PriorityCallback?
        var priority: Double?
        var throttle: Boolean?
        var throttleByServer: Boolean?
        var type: RequestType?
    }

    /**
     * The URL to request.
     * @see Online Documentation
     */
    var url: String

    /**
     * The function that makes the actual data request.
     * @see Online Documentation
     */
    var requestFunction: RequestCallback

    /**
     * The function that is called when the request is cancelled.
     * @see Online Documentation
     */
    var cancelFunction: CancelCallback

    /**
     * The function that is called to update the request's priority, which occurs once per frame.
     * @see Online Documentation
     */
    var priorityFunction: PriorityCallback

    /**
     * Priority is a unit-less value where lower values represent higher priority.
     * For world-based objects, this is usually the distance from the camera.
     * A request that does not have a priority function defaults to a priority of 0.
     *
     * If priorityFunction is defined, this value is updated every frame with the result of that call.
     * @see Online Documentation
     */
    var priority: Double

    /**
     * Whether to throttle and prioritize the request. If false, the request will be sent immediately. If true, the
     * request will be throttled and sent based on priority.
     * @see Online Documentation
     */
    val throttle: Boolean

    /**
     * Whether to throttle the request by server. Browsers typically support about 6-8 parallel connections
     * for HTTP/1 servers, and an unlimited amount of connections for HTTP/2 servers. Setting this value
     * to `true` is preferable for requests going through HTTP/1 servers.
     * @see Online Documentation
     */
    val throttleByServer: Boolean

    /**
     * Type of request.
     * @see Online Documentation
     */
    val type: RequestType

    /**
     * The current state of the request.
     * @see Online Documentation
     */
    val state: RequestState

    /**
     * Duplicates a Request instance.
     * @param [result] The object onto which to store the result.
     * @return The modified result parameter or a new Resource instance if one was not provided.
     * @see Online Documentation
     */
    fun clone(result: Request? = definedExternally): Request
}

/**
 * The function that makes the actual data request.
 * @see Online Documentation
 */
typealias RequestCallback = () -> kotlin.js.Promise

/**
 * The function that is called when the request is cancelled.
 * @see Online Documentation
 */
typealias CancelCallback = () -> Unit

/**
 * The function that is called to update the request's priority, which occurs once per frame.
 * @see Online Documentation
 */
typealias PriorityCallback = () -> Double

inline fun Request(
    block: Request.ConstructorOptions.() -> Unit,
): Request {
    val options: Request.ConstructorOptions = js("({})")
    block(options)
    return Request(options)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy