Skip to content

Commit 649a34d

Browse files
authored
Add typescript (#12)
1 parent a73782b commit 649a34d

File tree

20 files changed

+1442
-604
lines changed

20 files changed

+1442
-604
lines changed

.ember-cli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
Setting `isTypeScriptProject` to true will force the blueprint generators to generate TypeScript
44
rather than JavaScript by default, when a TypeScript version of a given blueprint is available.
55
*/
6-
"isTypeScriptProject": false
6+
"isTypeScriptProject": true
77
}

.eslintrc.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,11 @@
22

33
module.exports = {
44
root: true,
5-
parser: '@babel/eslint-parser',
5+
parser: '@typescript-eslint/parser',
66
parserOptions: {
77
ecmaVersion: 'latest',
8-
sourceType: 'module',
9-
requireConfigFile: false,
10-
babelOptions: {
11-
plugins: [
12-
['@babel/plugin-proposal-decorators', { decoratorsBeforeExport: true }],
13-
],
14-
},
158
},
16-
plugins: ['ember'],
9+
plugins: ['ember', '@typescript-eslint'],
1710
extends: [
1811
'eslint:recommended',
1912
'plugin:ember/recommended',
@@ -24,6 +17,15 @@ module.exports = {
2417
},
2518
rules: {},
2619
overrides: [
20+
// ts files
21+
{
22+
files: ['**/*.ts'],
23+
extends: [
24+
'plugin:@typescript-eslint/eslint-recommended',
25+
'plugin:@typescript-eslint/recommended',
26+
],
27+
rules: {},
28+
},
2729
// node files
2830
{
2931
files: [
@@ -38,9 +40,6 @@ module.exports = {
3840
'./config/**/*.js',
3941
'./tests/dummy/config/**/*.js',
4042
],
41-
parserOptions: {
42-
sourceType: 'script',
43-
},
4443
env: {
4544
browser: false,
4645
node: true,

.node-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18.20.2
1+
18.20.2

addon/services/clock.js

Lines changed: 0 additions & 108 deletions
This file was deleted.

addon/services/clock.ts

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/**
2+
* @module ember-clock
3+
*/
4+
import Service from '@ember/service';
5+
import { tracked } from '@glimmer/tracking';
6+
import { cancel, later } from '@ember/runloop';
7+
import type { Timer } from '@ember/runloop';
8+
import type Owner from '@ember/owner';
9+
import { registerDestructor } from '@ember/destroyable';
10+
11+
const Interval = 1000;
12+
13+
/**
14+
* ## ClockService
15+
*
16+
* The clock synchronizes to the local host's system clock and can be used to
17+
* display the time or to update time sensitive properties.
18+
*
19+
* @class ClockService
20+
* @namespace EmberClock
21+
*/
22+
export default class ClockService extends Service {
23+
disabled: boolean = false;
24+
25+
/**
26+
* @property hour
27+
*/
28+
@tracked hour: number = 0;
29+
30+
/**
31+
* @property minute
32+
*/
33+
@tracked minute: number = 0;
34+
35+
/**
36+
* @property second
37+
*/
38+
@tracked second: number = 0;
39+
40+
/**
41+
* Stores the next tick, so that it can be cancelled and the clock stopped.
42+
* @property nextTick
43+
* @private
44+
*/
45+
@tracked nextTick?: Timer;
46+
47+
/**
48+
* @property isTicking
49+
* @readonly
50+
*/
51+
get isTicking() {
52+
return Boolean(this.nextTick);
53+
}
54+
55+
/**
56+
* Call `start()`
57+
* @method constructor
58+
*/
59+
constructor(owner: Owner) {
60+
super(owner);
61+
this.start();
62+
registerDestructor(this, () => this.stop());
63+
}
64+
65+
/**
66+
* Start the clock
67+
*
68+
* @method start
69+
* @private
70+
*/
71+
start() {
72+
this.tick();
73+
}
74+
75+
/**
76+
* Stop the clock
77+
*
78+
* @method stop
79+
* @private
80+
*/
81+
stop() {
82+
cancel(this.nextTick);
83+
this.nextTick = undefined;
84+
}
85+
86+
/**
87+
* Set the time to the current time.
88+
* @method setTime
89+
* @private
90+
*/
91+
setTime() {
92+
const now = new Date();
93+
this.second = now.getSeconds();
94+
this.minute = now.getMinutes();
95+
this.hour = now.getHours();
96+
}
97+
98+
/**
99+
* Ticks the clock
100+
* @method tick
101+
* @private
102+
*/
103+
tick() {
104+
this.setTime();
105+
if (this.disabled) {
106+
return;
107+
}
108+
109+
this.nextTick = later(this, this.tick, Interval);
110+
}
111+
}
112+
113+
declare module '@ember/service' {
114+
interface Registry {
115+
clock: ClockService;
116+
}
117+
}

ember-cli-build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
44

55
module.exports = function (defaults) {
66
const app = new EmberAddon(defaults, {
7-
// Add options here
7+
'ember-cli-babel': { enableTypeScriptTransform: true },
88
});
99

1010
/*

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
module.exports = {
44
name: require('./package').name,
5+
6+
options: {
7+
'ember-cli-babel': { enableTypeScriptTransform: true },
8+
},
59
};

0 commit comments

Comments
 (0)