├── app ├── .gitkeep └── services │ └── clock.js ├── addon ├── .gitkeep └── services │ └── clock.js ├── vendor └── .gitkeep ├── tests ├── unit │ ├── .gitkeep │ └── services │ │ ├── clock-test.js │ │ └── clock-1sec-test.js ├── integration │ └── .gitkeep ├── dummy │ ├── app │ │ ├── helpers │ │ │ └── .gitkeep │ │ ├── models │ │ │ └── .gitkeep │ │ ├── routes │ │ │ └── .gitkeep │ │ ├── styles │ │ │ └── app.css │ │ ├── components │ │ │ ├── .gitkeep │ │ │ └── clock-demo.js │ │ ├── controllers │ │ │ └── .gitkeep │ │ ├── templates │ │ │ ├── components │ │ │ │ ├── .gitkeep │ │ │ │ └── clock-demo.hbs │ │ │ └── application.hbs │ │ ├── resolver.js │ │ ├── services │ │ │ ├── clock-1sec.js │ │ │ ├── clock-5sec.js │ │ │ └── clock-30sec.js │ │ ├── router.js │ │ ├── app.js │ │ └── index.html │ ├── config │ │ ├── optional-features.json │ │ ├── targets.js │ │ └── environment.js │ └── public │ │ └── robots.txt ├── helpers │ ├── destroy-app.js │ ├── resolver.js │ ├── start-app.js │ └── module-for-acceptance.js ├── test-helper.js ├── acceptance │ └── main-test.js ├── .jshintrc └── index.html ├── .watchmanconfig ├── .template-lintrc.js ├── blueprints ├── .jshintrc └── clock │ ├── files │ └── __root__ │ │ └── services │ │ └── __name__.js │ └── index.js ├── index.js ├── config ├── environment.js └── ember-try.js ├── .eslintignore ├── .ember-cli ├── .editorconfig ├── .gitignore ├── .npmignore ├── testem.js ├── ember-cli-build.js ├── LICENSE.md ├── .eslintrc.js ├── .travis.yml ├── package.json └── README.md /app/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /addon/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/unit/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/integration/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/dummy/app/helpers/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/dummy/app/models/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/dummy/app/routes/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/dummy/app/styles/app.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/dummy/app/components/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/dummy/app/controllers/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/components/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | { 2 | "ignore_dirs": ["tmp", "dist"] 3 | } 4 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/application.hbs: -------------------------------------------------------------------------------- 1 | {{clock-demo}} 2 | 3 | -------------------------------------------------------------------------------- /app/services/clock.js: -------------------------------------------------------------------------------- 1 | export { default } from 'ember-cli-clock/services/clock'; 2 | -------------------------------------------------------------------------------- /tests/dummy/config/optional-features.json: -------------------------------------------------------------------------------- 1 | { 2 | "jquery-integration": false 3 | } 4 | -------------------------------------------------------------------------------- /tests/dummy/public/robots.txt: -------------------------------------------------------------------------------- 1 | # http://www.robotstxt.org 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /.template-lintrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | extends: 'recommended' 5 | }; 6 | -------------------------------------------------------------------------------- /blueprints/.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "predef": [ 3 | "console" 4 | ], 5 | "strict": false 6 | } 7 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | name: require('./package').name 5 | }; 6 | -------------------------------------------------------------------------------- /tests/dummy/app/resolver.js: -------------------------------------------------------------------------------- 1 | import Resolver from 'ember-resolver'; 2 | 3 | export default Resolver; 4 | -------------------------------------------------------------------------------- /config/environment.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function(/* environment, appConfig */) { 4 | return { }; 5 | }; 6 | -------------------------------------------------------------------------------- /tests/dummy/app/services/clock-1sec.js: -------------------------------------------------------------------------------- 1 | import Clock from 'ember-cli-clock/services/clock'; 2 | 3 | export default Clock.extend({ 4 | interval: 1000 5 | }); 6 | -------------------------------------------------------------------------------- /tests/dummy/app/services/clock-5sec.js: -------------------------------------------------------------------------------- 1 | import Clock from 'ember-cli-clock/services/clock'; 2 | 3 | export default Clock.extend({ 4 | interval: 5000 5 | }); 6 | -------------------------------------------------------------------------------- /tests/dummy/app/services/clock-30sec.js: -------------------------------------------------------------------------------- 1 | import Clock from 'ember-cli-clock/services/clock'; 2 | 3 | export default Clock.extend({ 4 | interval: 30000 5 | }); 6 | -------------------------------------------------------------------------------- /tests/helpers/destroy-app.js: -------------------------------------------------------------------------------- 1 | import { run } from '@ember/runloop'; 2 | 3 | export default function destroyApp(application) { 4 | run(application, 'destroy'); 5 | } 6 | -------------------------------------------------------------------------------- /blueprints/clock/files/__root__/services/__name__.js: -------------------------------------------------------------------------------- 1 | import Clock from 'ember-cli-clock/services/clock'; 2 | 3 | export default Clock.extend({ 4 | interval: <%= interval %> 5 | }); 6 | -------------------------------------------------------------------------------- /tests/test-helper.js: -------------------------------------------------------------------------------- 1 | import Application from '../app'; 2 | import config from '../config/environment'; 3 | import { setApplication } from '@ember/test-helpers'; 4 | import { start } from 'ember-qunit'; 5 | 6 | setApplication(Application.create(config.APP)); 7 | 8 | start(); 9 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | # unconventional js 2 | /blueprints/*/files/ 3 | /vendor/ 4 | 5 | # compiled output 6 | /dist/ 7 | /tmp/ 8 | 9 | # dependencies 10 | /bower_components/ 11 | 12 | # misc 13 | /coverage/ 14 | 15 | # ember-try 16 | /.node_modules.ember-try/ 17 | /bower.json.ember-try 18 | /package.json.ember-try 19 | -------------------------------------------------------------------------------- /tests/dummy/app/router.js: -------------------------------------------------------------------------------- 1 | import EmberRouter from '@ember/routing/router'; 2 | import config from './config/environment'; 3 | 4 | const Router = EmberRouter.extend({ 5 | location: config.locationType, 6 | rootURL: config.rootURL 7 | }); 8 | 9 | Router.map(function() { 10 | }); 11 | 12 | export default Router; 13 | -------------------------------------------------------------------------------- /.ember-cli: -------------------------------------------------------------------------------- 1 | { 2 | /** 3 | Ember CLI sends analytics information by default. The data is completely 4 | anonymous, but there are times when you might want to disable this behavior. 5 | 6 | Setting `disableAnalytics` to true will prevent any data from being sent. 7 | */ 8 | "disableAnalytics": false 9 | } 10 | -------------------------------------------------------------------------------- /tests/helpers/resolver.js: -------------------------------------------------------------------------------- 1 | import Resolver from 'ember/resolver'; 2 | import config from '../../config/environment'; 3 | 4 | const resolver = Resolver.create(); 5 | 6 | resolver.namespace = { 7 | modulePrefix: config.modulePrefix, 8 | podModulePrefix: config.podModulePrefix 9 | }; 10 | 11 | export default resolver; 12 | -------------------------------------------------------------------------------- /blueprints/clock/index.js: -------------------------------------------------------------------------------- 1 | /*jshint node:true*/ 2 | 3 | module.exports = { 4 | description: 'Generates an ember-cli-clock service.', 5 | 6 | availableOptions: [ 7 | { name: 'interval', type: Number, default: 1000 } 8 | ], 9 | 10 | locals: function(options) { 11 | return { 12 | interval: options.interval 13 | }; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /tests/dummy/config/targets.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const browsers = [ 4 | 'last 1 Chrome versions', 5 | 'last 1 Firefox versions', 6 | 'last 1 Safari versions' 7 | ]; 8 | 9 | const isCI = !!process.env.CI; 10 | const isProduction = process.env.EMBER_ENV === 'production'; 11 | 12 | if (isCI || isProduction) { 13 | browsers.push('ie 11'); 14 | } 15 | 16 | module.exports = { 17 | browsers 18 | }; 19 | -------------------------------------------------------------------------------- /tests/dummy/app/components/clock-demo.js: -------------------------------------------------------------------------------- 1 | import Component from '@ember/component'; 2 | import { inject as service } from '@ember/service'; 3 | 4 | export default Component.extend({ 5 | clock: service(), 6 | 'clock-1sec': service(), 7 | 'clock-5sec': service(), 8 | 'clock-30sec': service(), 9 | 10 | actions: { 11 | reset() { 12 | this.get('clock').reset(); 13 | }, 14 | }, 15 | }); 16 | -------------------------------------------------------------------------------- /tests/dummy/app/app.js: -------------------------------------------------------------------------------- 1 | import Application from '@ember/application'; 2 | import Resolver from './resolver'; 3 | import loadInitializers from 'ember-load-initializers'; 4 | import config from './config/environment'; 5 | 6 | const App = Application.extend({ 7 | modulePrefix: config.modulePrefix, 8 | podModulePrefix: config.podModulePrefix, 9 | Resolver 10 | }); 11 | 12 | loadInitializers(App, config.modulePrefix); 13 | 14 | export default App; 15 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | 8 | [*] 9 | end_of_line = lf 10 | charset = utf-8 11 | trim_trailing_whitespace = true 12 | insert_final_newline = true 13 | indent_style = space 14 | indent_size = 2 15 | 16 | [*.hbs] 17 | insert_final_newline = false 18 | 19 | [*.{diff,md}] 20 | trim_trailing_whitespace = false 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist/ 5 | /tmp/ 6 | 7 | # dependencies 8 | /bower_components/ 9 | /node_modules/ 10 | 11 | # misc 12 | /.sass-cache 13 | /connect.lock 14 | /coverage/ 15 | /libpeerconnection.log 16 | /npm-debug.log* 17 | /testem.log 18 | /yarn-error.log 19 | /.idea 20 | 21 | # ember-try 22 | /.node_modules.ember-try/ 23 | /bower.json.ember-try 24 | /package.json.ember-try 25 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist/ 3 | /tmp/ 4 | 5 | # dependencies 6 | /bower_components/ 7 | 8 | # misc 9 | /.bowerrc 10 | /.editorconfig 11 | /.ember-cli 12 | /.eslintignore 13 | /.eslintrc.js 14 | /.gitignore 15 | /.watchmanconfig 16 | /.travis.yml 17 | /bower.json 18 | /config/ember-try.js 19 | /ember-cli-build.js 20 | /testem.js 21 | /tests/ 22 | /yarn.lock 23 | .gitkeep 24 | 25 | # ember-try 26 | /.node_modules.ember-try/ 27 | /bower.json.ember-try 28 | /package.json.ember-try 29 | -------------------------------------------------------------------------------- /tests/acceptance/main-test.js: -------------------------------------------------------------------------------- 1 | import { module, test } from 'qunit'; 2 | import { visit } from '@ember/test-helpers'; 3 | import { setupApplicationTest } from 'ember-qunit'; 4 | import { later } from '@ember/runloop' 5 | 6 | module('Acceptance | main', function(hooks) { 7 | setupApplicationTest(hooks); 8 | 9 | test('visiting /', async function(assert) { 10 | await visit('/'); 11 | 12 | later(() => { 13 | assert.equal(this.element.querySelector('ul li').textContent, '1 seconds', 'Verify that the clock ticks once'); 14 | }, 1100); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /tests/helpers/start-app.js: -------------------------------------------------------------------------------- 1 | import { merge } from '@ember/polyfills'; 2 | import { run } from '@ember/runloop'; 3 | import Application from '../../app'; 4 | import config from '../../config/environment'; 5 | 6 | export default function startApp(attrs) { 7 | let application; 8 | 9 | let attributes = merge({}, config.APP); 10 | attributes = merge(attributes, attrs); // use defaults, but you can override; 11 | 12 | run(() => { 13 | application = Application.create(attributes); 14 | application.setupForTesting(); 15 | application.injectTestHelpers(); 16 | }); 17 | 18 | return application; 19 | } 20 | -------------------------------------------------------------------------------- /tests/helpers/module-for-acceptance.js: -------------------------------------------------------------------------------- 1 | import { module } from 'qunit'; 2 | import startApp from '../helpers/start-app'; 3 | import destroyApp from '../helpers/destroy-app'; 4 | 5 | export default function(name, options = {}) { 6 | module(name, { 7 | beforeEach() { 8 | this.application = startApp(); 9 | 10 | if (options.beforeEach) { 11 | options.beforeEach.apply(this, arguments); 12 | } 13 | }, 14 | 15 | afterEach() { 16 | destroyApp(this.application); 17 | 18 | if (options.afterEach) { 19 | options.afterEach.apply(this, arguments); 20 | } 21 | } 22 | }); 23 | } 24 | -------------------------------------------------------------------------------- /testem.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | test_page: 'tests/index.html?hidepassed', 3 | disable_watching: true, 4 | launch_in_ci: [ 5 | 'Chrome' 6 | ], 7 | launch_in_dev: [ 8 | 'Chrome' 9 | ], 10 | browser_args: { 11 | Chrome: { 12 | ci: [ 13 | // --no-sandbox is needed when running Chrome inside a container 14 | process.env.CI ? '--no-sandbox' : null, 15 | '--headless', 16 | '--disable-gpu', 17 | '--disable-dev-shm-usage', 18 | '--disable-software-rasterizer', 19 | '--mute-audio', 20 | '--remote-debugging-port=0', 21 | '--window-size=1440,900' 22 | ].filter(Boolean) 23 | } 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /ember-cli-build.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); 4 | 5 | module.exports = function(defaults) { 6 | let app = new EmberAddon(defaults, { 7 | // Add options here 8 | }); 9 | 10 | /* 11 | This build file specifies the options for the dummy test app of this 12 | addon, located in `/tests/dummy` 13 | This build file does *not* influence how the addon or the app using it 14 | behave. You most likely want to be modifying `./index.js` or app's build file 15 | */ 16 | 17 | app.import('node_modules/lolex/lolex.js', { 18 | using: [ 19 | { transformation: 'amd', as: 'lolex' } 20 | ], 21 | type: 'test' 22 | }); 23 | 24 | return app.toTree(); 25 | }; 26 | -------------------------------------------------------------------------------- /tests/dummy/app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Dummy 7 | 8 | 9 | 10 | {{content-for "head"}} 11 | 12 | 13 | 14 | 15 | {{content-for "head-footer"}} 16 | 17 | 18 | {{content-for "body"}} 19 | 20 | 21 | 22 | 23 | {{content-for "body-footer"}} 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/components/clock-demo.hbs: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | 11 |

Alternative

12 | 13 | 18 | 19 |

20 | Use these clocks for updating displayed dates or other background work where 21 | you need to observe a "tick" on a second or minute frequency. 22 |

23 | 24 |

25 | Download the code 26 |

27 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /tests/.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "predef": [ 3 | "document", 4 | "window", 5 | "location", 6 | "setTimeout", 7 | "$", 8 | "-Promise", 9 | "define", 10 | "console", 11 | "visit", 12 | "exists", 13 | "fillIn", 14 | "click", 15 | "keyEvent", 16 | "triggerEvent", 17 | "find", 18 | "findWithAssert", 19 | "wait", 20 | "DS", 21 | "andThen", 22 | "currentURL", 23 | "currentPath", 24 | "currentRouteName", 25 | "lolex" 26 | ], 27 | "node": false, 28 | "browser": false, 29 | "boss": true, 30 | "curly": true, 31 | "debug": false, 32 | "devel": false, 33 | "eqeqeq": true, 34 | "evil": true, 35 | "forin": false, 36 | "immed": false, 37 | "laxbreak": false, 38 | "newcap": true, 39 | "noarg": true, 40 | "noempty": false, 41 | "nonew": false, 42 | "nomen": false, 43 | "onevar": false, 44 | "plusplus": false, 45 | "regexp": false, 46 | "undef": true, 47 | "sub": true, 48 | "strict": false, 49 | "white": false, 50 | "eqnull": true, 51 | "esnext": true, 52 | "unused": true 53 | } 54 | -------------------------------------------------------------------------------- /tests/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Dummy Tests 7 | 8 | 9 | 10 | {{content-for "head"}} 11 | {{content-for "test-head"}} 12 | 13 | 14 | 15 | 16 | 17 | {{content-for "head-footer"}} 18 | {{content-for "test-head-footer"}} 19 | 20 | 21 | {{content-for "body"}} 22 | {{content-for "test-body"}} 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | {{content-for "body-footer"}} 31 | {{content-for "test-body-footer"}} 32 | 33 | 34 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | parserOptions: { 4 | ecmaVersion: 2017, 5 | sourceType: 'module' 6 | }, 7 | plugins: [ 8 | 'ember' 9 | ], 10 | extends: [ 11 | 'eslint:recommended', 12 | 'plugin:ember/recommended' 13 | ], 14 | env: { 15 | browser: true 16 | }, 17 | rules: { 18 | }, 19 | overrides: [ 20 | // node files 21 | { 22 | files: [ 23 | '.template-lintrc.js', 24 | 'ember-cli-build.js', 25 | 'index.js', 26 | 'testem.js', 27 | 'blueprints/*/index.js', 28 | 'config/**/*.js', 29 | 'tests/dummy/config/**/*.js' 30 | ], 31 | excludedFiles: [ 32 | 'addon/**', 33 | 'addon-test-support/**', 34 | 'app/**', 35 | 'tests/dummy/app/**' 36 | ], 37 | parserOptions: { 38 | sourceType: 'script', 39 | ecmaVersion: 2015 40 | }, 41 | env: { 42 | browser: false, 43 | node: true 44 | }, 45 | plugins: ['node'], 46 | rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, { 47 | // add your custom rules and overrides for node files here 48 | }) 49 | } 50 | ] 51 | }; 52 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: node_js 3 | node_js: 4 | # we recommend testing addons with the same minimum supported node version as Ember CLI 5 | # so that your addon works for all apps 6 | - "6" 7 | 8 | sudo: false 9 | dist: trusty 10 | 11 | addons: 12 | chrome: stable 13 | 14 | cache: 15 | directories: 16 | - $HOME/.npm 17 | 18 | env: 19 | global: 20 | # See https://git.io/vdao3 for details. 21 | - JOBS=1 22 | 23 | jobs: 24 | fail_fast: true 25 | allow_failures: 26 | - env: EMBER_TRY_SCENARIO=ember-canary 27 | 28 | include: 29 | # runs linting and tests with current locked deps 30 | 31 | - stage: "Tests" 32 | name: "Tests" 33 | script: 34 | - npm run lint:hbs 35 | - npm run lint:js 36 | - npm test 37 | 38 | # we recommend new addons test the current and previous LTS 39 | # as well as latest stable release (bonus points to beta/canary) 40 | - stage: "Additional Tests" 41 | env: EMBER_TRY_SCENARIO=ember-lts-2.16 42 | - env: EMBER_TRY_SCENARIO=ember-lts-2.18 43 | - env: EMBER_TRY_SCENARIO=ember-release 44 | - env: EMBER_TRY_SCENARIO=ember-beta 45 | - env: EMBER_TRY_SCENARIO=ember-canary 46 | - env: EMBER_TRY_SCENARIO=ember-default-with-jquery 47 | 48 | before_install: 49 | - npm config set spin false 50 | - npm install -g npm@4 51 | - npm --version 52 | 53 | script: 54 | - node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO 55 | -------------------------------------------------------------------------------- /tests/dummy/config/environment.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function(environment) { 4 | let ENV = { 5 | modulePrefix: 'dummy', 6 | environment, 7 | rootURL: '/', 8 | locationType: 'auto', 9 | EmberENV: { 10 | FEATURES: { 11 | // Here you can enable experimental features on an ember canary build 12 | // e.g. 'with-controller': true 13 | }, 14 | EXTEND_PROTOTYPES: { 15 | // Prevent Ember Data from overriding Date.parse. 16 | Date: false 17 | } 18 | }, 19 | 20 | APP: { 21 | // Here you can pass flags/options to your application instance 22 | // when it is created 23 | } 24 | }; 25 | 26 | if (environment === 'development') { 27 | // ENV.APP.LOG_RESOLVER = true; 28 | // ENV.APP.LOG_ACTIVE_GENERATION = true; 29 | // ENV.APP.LOG_TRANSITIONS = true; 30 | // ENV.APP.LOG_TRANSITIONS_INTERNAL = true; 31 | // ENV.APP.LOG_VIEW_LOOKUPS = true; 32 | } 33 | 34 | if (environment === 'test') { 35 | // Testem prefers this... 36 | ENV.locationType = 'none'; 37 | 38 | // keep test console output quieter 39 | ENV.APP.LOG_ACTIVE_GENERATION = false; 40 | ENV.APP.LOG_VIEW_LOOKUPS = false; 41 | 42 | ENV.APP.rootElement = '#ember-testing'; 43 | ENV.APP.autoboot = false; 44 | } 45 | 46 | if (environment === 'production') { 47 | // here you can enable a production-specific feature 48 | } 49 | 50 | return ENV; 51 | }; 52 | -------------------------------------------------------------------------------- /tests/unit/services/clock-test.js: -------------------------------------------------------------------------------- 1 | import lolex from 'lolex'; 2 | import { module, test } from 'qunit'; 3 | import { setupTest } from 'ember-qunit'; 4 | 5 | module('Unit | Service | clock', function(hooks) { 6 | setupTest(hooks); 7 | 8 | hooks.beforeEach(function() { 9 | this.fakeClock = lolex.install(); 10 | }); 11 | 12 | hooks.afterEach(function() { 13 | this.fakeClock.uninstall(); 14 | }); 15 | 16 | test('assert that clock will tick two seconds accurately', function(assert) { 17 | const clock = this.owner.lookup('service:clock'); 18 | assert.equal(clock.get('second'), 0, 'The clock has not ticked yet'); 19 | 20 | this.fakeClock.tick(2100); 21 | assert.equal(clock.get('second'), 2, 'The clock has ticked twice at 1 second intervals'); 22 | }); 23 | 24 | test('assert that the interval timing can be changed', function(assert) { 25 | const clock = this.owner.lookup('service:clock'); 26 | assert.equal(clock.get('second'), 0, 'The clock has not ticked yet'); 27 | 28 | clock.set('intervalTime', 100); 29 | assert.equal(clock.get('second'), 0, 'The clock has not ticked yet'); 30 | 31 | this.fakeClock.tick(250); 32 | assert.equal(clock.get('second'), 2, 'The clock has ticked twice at 100ms intervals'); 33 | }); 34 | 35 | test('assert that all counts are incrementing accurately', function(assert) { 36 | const clock = this.owner.lookup('service:clock'); 37 | 38 | this.fakeClock.tick(7200000); 39 | 40 | let vals = clock.getProperties('second', 'minute', 'five', 'quarter', 'hour'); 41 | assert.ok(vals.second === 7200, 'Seconds are accurate'); 42 | assert.ok(vals.minute === 120, 'Minutes are accurate'); 43 | assert.ok(vals.five === 24, 'Five minute increments are accurate'); 44 | assert.ok(vals.quarter === 8, 'Quarter hour increments are accurate'); 45 | assert.ok(vals.hour === 2, 'Hours are accurate'); 46 | }); 47 | }); 48 | -------------------------------------------------------------------------------- /tests/unit/services/clock-1sec-test.js: -------------------------------------------------------------------------------- 1 | import lolex from 'lolex'; 2 | import { module, test } from 'qunit'; 3 | import { setupTest } from 'ember-qunit'; 4 | 5 | // 2016-02-03T11:50:53Z 6 | const START_TIME = 1454500253000; 7 | 8 | module('Unit | Service | clock-1sec', function(hooks) { 9 | setupTest(hooks); 10 | 11 | hooks.beforeEach(function() { 12 | this.fakeClock = lolex.install(); 13 | this.fakeClock.tick(START_TIME); 14 | }); 15 | 16 | hooks.afterEach(function() { 17 | this.fakeClock.uninstall(); 18 | }); 19 | 20 | test('assert that clock will tick two seconds accurately', function(assert) { 21 | const clock = this.owner.lookup('service:clock'); 22 | assert.equal(clock.get('time'), START_TIME, 'The clock has not ticked yet'); 23 | 24 | this.fakeClock.tick(999); 25 | assert.equal(clock.get('time'), START_TIME, 'The clock has not ticked yet'); 26 | 27 | this.fakeClock.tick(1); 28 | assert.equal(clock.get('time'), START_TIME + 1000, 'The clock has ticked once'); 29 | 30 | this.fakeClock.tick(1100); 31 | assert.equal(clock.get('time'), START_TIME + 2000, 'The clock has ticked twice at 1 second intervals'); 32 | }); 33 | 34 | test('assert that the interval timing can be changed', function(assert) { 35 | const clock = this.owner.lookup('service:clock'); 36 | assert.equal(clock.get('time'), START_TIME, 'The clock has not ticked yet'); 37 | 38 | clock.set('interval', 100); 39 | assert.equal(clock.get('time'), START_TIME, 'The clock has not ticked yet'); 40 | 41 | this.fakeClock.tick(99); 42 | assert.equal(clock.get('time'), START_TIME, 'The clock has not ticked yet'); 43 | 44 | this.fakeClock.tick(1); 45 | assert.equal(clock.get('time'), START_TIME + 100, 'The clock has ticked once'); 46 | 47 | this.fakeClock.tick(110); 48 | assert.equal(clock.get('time'), START_TIME + 200, 'The clock has ticked twice at 100ms intervals'); 49 | }); 50 | 51 | }); 52 | 53 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ember-cli-clock", 3 | "version": "3.0.0", 4 | "description": "The default blueprint for ember-cli addons.", 5 | "keywords": [ 6 | "ember-addon", 7 | "clock", 8 | "update", 9 | "ember", 10 | "emberjs", 11 | "timer" 12 | ], 13 | "repository": "https://github.com/jerel/ember-cli-clock.git", 14 | "license": "MIT", 15 | "author": "Jerel Unruh", 16 | "bugs": { 17 | "url": "https://github.com/jerel/ember-cli-clock/issues" 18 | }, 19 | "homepage": "https://github.com/jerel/ember-cli-clock", 20 | "directories": { 21 | "doc": "doc", 22 | "test": "tests" 23 | }, 24 | "scripts": { 25 | "build": "ember build", 26 | "lint:hbs": "ember-template-lint .", 27 | "lint:js": "eslint .", 28 | "start": "ember serve", 29 | "test": "ember test", 30 | "test:all": "ember try:each" 31 | }, 32 | "dependencies": { 33 | "ember-cli-babel": "^6.16.0" 34 | }, 35 | "devDependencies": { 36 | "@ember/optional-features": "^0.6.3", 37 | "broccoli-asset-rev": "^2.7.0", 38 | "ember-ajax": "^3.1.0", 39 | "ember-cli": "~3.4.3", 40 | "ember-cli-dependency-checker": "^3.0.0", 41 | "ember-cli-eslint": "^4.2.3", 42 | "ember-cli-htmlbars": "^3.0.0", 43 | "ember-cli-htmlbars-inline-precompile": "^1.0.3", 44 | "ember-cli-inject-live-reload": "^1.8.2", 45 | "ember-cli-qunit": "^4.3.2", 46 | "ember-cli-sri": "^2.1.1", 47 | "ember-cli-template-lint": "^1.0.0-beta.1", 48 | "ember-cli-uglify": "^2.1.0", 49 | "ember-disable-prototype-extensions": "^1.1.3", 50 | "ember-export-application-global": "^2.0.0", 51 | "ember-load-initializers": "^1.1.0", 52 | "ember-maybe-import-regenerator": "^0.1.6", 53 | "ember-resolver": "^5.0.1", 54 | "ember-source": "~3.4.0", 55 | "ember-source-channel-url": "^1.1.0", 56 | "ember-try": "^1.0.0", 57 | "eslint-plugin-ember": "^5.2.0", 58 | "eslint-plugin-node": "^7.0.1", 59 | "loader.js": "^4.7.0", 60 | "lolex": "^3.0.0", 61 | "qunit-dom": "^0.7.1" 62 | }, 63 | "engines": { 64 | "node": "6.* || 8.* || >= 10.*" 65 | }, 66 | "ember-addon": { 67 | "configPath": "tests/dummy/config" 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /config/ember-try.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const getChannelURL = require('ember-source-channel-url'); 4 | 5 | module.exports = function() { 6 | return Promise.all([ 7 | getChannelURL('release'), 8 | getChannelURL('beta'), 9 | getChannelURL('canary') 10 | ]).then((urls) => { 11 | return { 12 | scenarios: [ 13 | { 14 | name: 'ember-lts-2.16', 15 | env: { 16 | EMBER_OPTIONAL_FEATURES: JSON.stringify({ 'jquery-integration': true }), 17 | }, 18 | npm: { 19 | devDependencies: { 20 | '@ember/jquery': '^0.5.1', 21 | 'ember-source': '~2.16.0' 22 | } 23 | } 24 | }, 25 | { 26 | name: 'ember-lts-2.18', 27 | env: { 28 | EMBER_OPTIONAL_FEATURES: JSON.stringify({ 'jquery-integration': true }), 29 | }, 30 | npm: { 31 | devDependencies: { 32 | '@ember/jquery': '^0.5.1', 33 | 'ember-source': '~2.18.0' 34 | } 35 | } 36 | }, 37 | { 38 | name: 'ember-release', 39 | npm: { 40 | devDependencies: { 41 | 'ember-source': urls[0] 42 | } 43 | } 44 | }, 45 | { 46 | name: 'ember-beta', 47 | npm: { 48 | devDependencies: { 49 | 'ember-source': urls[1] 50 | } 51 | } 52 | }, 53 | { 54 | name: 'ember-canary', 55 | npm: { 56 | devDependencies: { 57 | 'ember-source': urls[2] 58 | } 59 | } 60 | }, 61 | { 62 | name: 'ember-default', 63 | npm: { 64 | devDependencies: {} 65 | } 66 | }, 67 | { 68 | name: 'ember-default-with-jquery', 69 | env: { 70 | EMBER_OPTIONAL_FEATURES: JSON.stringify({ 71 | 'jquery-integration': true 72 | }) 73 | }, 74 | npm: { 75 | devDependencies: { 76 | '@ember/jquery': '^0.5.1' 77 | } 78 | } 79 | } 80 | ] 81 | }; 82 | }); 83 | }; 84 | -------------------------------------------------------------------------------- /addon/services/clock.js: -------------------------------------------------------------------------------- 1 | import Service from '@ember/service'; 2 | import { computed, observer } from '@ember/object'; 3 | import { run } from '@ember/runloop'; 4 | import Ember from 'ember'; 5 | 6 | export default Service.extend({ 7 | 8 | interval: 1000, 9 | intervalTime: 1000, 10 | second: 0, 11 | minute: 0, 12 | five: 0, 13 | quarter: 0, 14 | hour: 0, 15 | time: null, 16 | 17 | date: computed('time', function() { 18 | return new Date(this.get('time')); 19 | }), 20 | 21 | init() { 22 | this._super(...arguments); 23 | this.start(); 24 | }, 25 | 26 | start() { 27 | this.update(); 28 | this.set('intervalId', window.setInterval(() => this.update(), this.get('interval'))); 29 | }, 30 | 31 | stop() { 32 | window.clearInterval(this.get('intervalId')); 33 | }, 34 | 35 | willDestroy() { 36 | this._super(...arguments); 37 | this.stop(); 38 | }, 39 | 40 | onIntervalChange: observer('interval', function() { 41 | this.stop(); 42 | this.start(); 43 | }), 44 | 45 | update() { 46 | run(() => this.set('time', Date.now())); 47 | }, 48 | 49 | reset() { 50 | this.stop(); 51 | this.setProperties({second: 0, minute: 0, five: 0, quarter: 0, hour: 0}); 52 | this.start(); 53 | }, 54 | 55 | intervalChange: observer('intervalTime', function() { 56 | if (Ember.testing) { 57 | this.set('interval', this.get('intervalTime')); 58 | return this.reset(); 59 | } 60 | throw Error('The clock interval cannot be changed except during testing'); 61 | }), 62 | 63 | timeChange: observer('time', function() { 64 | this.tick(); 65 | }), 66 | 67 | tick() { 68 | let second = this.incrementProperty('second'); 69 | 70 | if (second && (second % 60) === 0) { 71 | let minute = this.incrementProperty('minute'); 72 | 73 | if (minute !== 0) { 74 | if ((minute % 5) === 0) { 75 | this.incrementProperty('five'); 76 | } 77 | 78 | if ((minute % 15) === 0) { 79 | this.incrementProperty('quarter'); 80 | } 81 | 82 | if ((minute % 60) === 0) { 83 | this.incrementProperty('hour'); 84 | } 85 | } 86 | } 87 | } 88 | 89 | }); 90 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ember-cli-clock 2 | 3 | [![Build Status](https://travis-ci.org/jerel/ember-cli-clock.svg?branch=master)](https://travis-ci.org/jerel/ember-cli-clock) 4 | 5 | A simple clock service for Ember.js 6 | 7 | 8 | ## Live Demo 9 | 10 | View a live demo here: 11 | 12 | 13 | ## Installation 14 | 15 | `ember install ember-cli-clock` 16 | 17 | 18 | ## Usage 19 | 20 | 1. Generate a clock service 21 | 22 | `ember generate clock my-shiny-new-clock` 23 | 24 | 2. Inject the `my-shiny-new-clock` service into your component, controller, 25 | route, ... 26 | 27 | `clock: service('my-shiny-new-clock')` 28 | 29 | 3. Use the `time` (`Date.now()`) and `date` (`Date` instance) properties 30 | of the clock service 31 | 32 | 33 | ## Examples 34 | 35 | ```js 36 | // app/components/iso-date.js 37 | import Component from '@ember/component'; 38 | import { inject as service } from '@ember/service'; 39 | import { computed } from '@ember/object'; 40 | 41 | export default Component.extend({ 42 | clock: service('my-shiny-new-clock'), 43 | 44 | iso: computed('clock.date', function() { 45 | return this.get('clock.date').toISOString(); 46 | }) 47 | }); 48 | ``` 49 | 50 | Using `{{iso}}` in the template will output something like 51 | `2011-10-05T14:48:00.000Z` and update it every second. 52 | 53 | 54 | ```js 55 | // app/components/device-status.js 56 | import Component from '@ember/component'; 57 | import { inject as service } from '@ember/service'; 58 | import { computed } from '@ember/object'; 59 | 60 | export default Component.extend({ 61 | clock: service('my-shiny-new-clock'), 62 | 63 | isOnline: computed('lastContact', 'clock.time', function() { 64 | return this.get('clock.time') - this.get('lastContact') < 60 * 1000; 65 | }) 66 | }); 67 | ``` 68 | 69 | The `isOnline` property is updated every second and will tell 70 | if the last contact of the device was less than 60 seconds ago. 71 | 72 | 73 | ## API 74 | 75 | ### Properties 76 | 77 | - `interval` (default: 1000ms) - the update interval of `time` and `date` 78 | - `time` (read-only) - will be set to `Date.now()` every `interval` milliseconds 79 | - `date` (read-only) - computed property: `new Date(this.get('time'))` 80 | 81 | ### Methods 82 | 83 | - `start()` - starts the clock after it has been stopped 84 | - `stop()` - stops the clock from updating `time` and `date` until restarted 85 | 86 | 87 | ## Authors 88 | 89 | * [Jerel Unruh](http://twitter.com/jerelunruh/) 90 | * [Tobias Bieniek](https://github.com/Turbo87) 91 | * [Andy Rohr](https://github.com/arohr) 92 | 93 | ## Legal 94 | 95 | Copyright (c) 2014 Jerel Unruh and contributors 96 | 97 | [Licensed under the MIT license](http://www.opensource.org/licenses/mit-license.php) 98 | --------------------------------------------------------------------------------