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).
Methods
emit
-
event
-
payload
Emits an event to the instance: calls all event listeners subscribed to this event, or the 'any' event.
Parameters:
-
event
StringEvent
-
payload
An object passed as parameter to all event listeners.
getEstimatedTime
()
Number
Returns the estimated time to load the resource. Can be overridden.
Returns:
The estimated time
load
-
onFinish
-
onError
-
onProgress
Called when the resource is needed to load.
Parameters:
-
onFinish
Functionhave to be called when the resource is finished
-
onError
Functionhave to be called when an error occurs
-
onProgress
Functionmay be called when the progress changes (value in percent)
off
-
event
-
listener
Unsubscribes from an event.
Parameters:
-
event
StringEvent
-
listener
FunctionEvent listener
on
-
event
-
listener
Subscribes to an event. The event handler will be called with this instance as context.
Parameters:
-
event
StringThe event to subscribe
-
listener
FunctionEvent listener
Events
any
Emitted when any event is emitted. The parameters are the event and the payload.