Skip to content
Ember-CLI addon that provides a service to keep the current time synced as a computed property and supports remote timestamp fetching.
JavaScript HTML
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
addon
app
blueprints
config
tests
vendor
.bowerrc
.editorconfig
.ember-cli
.gitignore
.jshintrc
.npmignore
.travis.yml
.watchmanconfig
LICENSE.md
README.md
bower.json
ember-cli-build.js
index.js
package.json
testem.js
testem.json

README.md

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 updated
  • useRemoteTimestamp: (Default: false) Let the service know to sync with a server
  • remoteSyncFrequency: (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
  • timestampEndpoint: (Required if useRemoteTimestamp is true) The URL to make a GET request to that will return an object that contains a timestamp
  • timestampProperty: (Required if useRemoteTimestamp is true) The name of the property in the object returned by timestampEndpoint
You can’t perform that action at this time.