ember-tick-tock
v1.0.3
Published
Bind computed properties to the current time. Supports remote timestamp syncing.
Downloads
18
Readme
ember-tick-tock
Installation
ember install ember-tick-tock
About
This Ember-CLI add-on provides a ticktock
service that will keep the current time synced in your application. In any component/controller/model/etc you can inject the service with the following line:
ticktock: Ember.inject.service()
Then, you will have access to the current time (a Moment.js object) by accessing the now
computed property in the service
isExpired: Ember.computed('expiresAt', 'ticktock.now', function() {
return this.get('expiresAt') <= this.get('ticktock.now');
}
Options
For some applications, when you cannot rely on the end-user's clock, you may need to use a remote endpoint to get the current time. You can pass an options object in your applications config/environment.js
file.
ENV['ticktockOptions'] = {
tickTockFrequency: 1,
useRemoteTimestamp: true,
remoteSyncFrequency: 60,
timestampEndpoint: ENV.apiServer + '/timestamp',
timestampProperty: 'time'
};
tickTockFrequency
: (Default:1
) How often (in seconds) should timestamp be updateduseRemoteTimestamp
: (Default:false
) Let the service know to sync with a serverremoteSyncFrequency
: (Default:60
) How often to ping the server (in seconds) to get an updated timestamp- The service will still update the
now
property every second, regardless of this value
- The service will still update the
timestampEndpoint
: (Required ifuseRemoteTimestamp
is true) The URL to make aGET
request to that will return an object that contains a timestamptimestampProperty
: (Required ifuseRemoteTimestamp
is true) The name of the property in the object returned bytimestampEndpoint