API Docs for: 1.0.1

Grape.Resource Class

An abstract class to represent a resource. A resource can load itself, and can tell the estimated time to load it (default:1).

Item Index

Events

Methods

emit

(
  • event
  • payload
)

Emits an event to the instance: calls all event listeners subscribed to this event, or the 'any' event.

Parameters:

  • event String

    Event

  • payload

    An object passed as parameter to all event listeners.

getEstimatedTime

() Number

Returns the estimated time to load the resource. Can be overridden.

Returns:

Number:

The estimated time

load

(
  • onFinish
  • onError
  • onProgress
)

Called when the resource is needed to load.

Parameters:

  • onFinish Function

    have to be called when the resource is finished

  • onError Function

    have to be called when an error occurs

  • onProgress Function

    may be called when the progress changes (value in percent)

off

(
  • event
  • listener
)

Unsubscribes from an event.

Parameters:

  • event String

    Event

  • listener Function

    Event listener

on

(
  • event
  • listener
)

Subscribes to an event. The event handler will be called with this instance as context.

Parameters:

  • event String

    The event to subscribe

  • listener Function

    Event listener

Events

any

Emitted when any event is emitted. The parameters are the event and the payload.