Skip to content

Commit

Permalink
Add typescript (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
lozjackson authored May 17, 2024
1 parent a73782b commit 649a34d
Show file tree
Hide file tree
Showing 20 changed files with 1,442 additions and 604 deletions.
2 changes: 1 addition & 1 deletion .ember-cli
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
Setting `isTypeScriptProject` to true will force the blueprint generators to generate TypeScript
rather than JavaScript by default, when a TypeScript version of a given blueprint is available.
*/
"isTypeScriptProject": false
"isTypeScriptProject": true
}
23 changes: 11 additions & 12 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@

module.exports = {
root: true,
parser: '@babel/eslint-parser',
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
requireConfigFile: false,
babelOptions: {
plugins: [
['@babel/plugin-proposal-decorators', { decoratorsBeforeExport: true }],
],
},
},
plugins: ['ember'],
plugins: ['ember', '@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:ember/recommended',
Expand All @@ -24,6 +17,15 @@ module.exports = {
},
rules: {},
overrides: [
// ts files
{
files: ['**/*.ts'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {},
},
// node files
{
files: [
Expand All @@ -38,9 +40,6 @@ module.exports = {
'./config/**/*.js',
'./tests/dummy/config/**/*.js',
],
parserOptions: {
sourceType: 'script',
},
env: {
browser: false,
node: true,
Expand Down
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.20.2
18.20.2
108 changes: 0 additions & 108 deletions addon/services/clock.js

This file was deleted.

117 changes: 117 additions & 0 deletions addon/services/clock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/**
* @module ember-clock
*/
import Service from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { cancel, later } from '@ember/runloop';
import type { Timer } from '@ember/runloop';
import type Owner from '@ember/owner';
import { registerDestructor } from '@ember/destroyable';

const Interval = 1000;

/**
* ## ClockService
*
* The clock synchronizes to the local host's system clock and can be used to
* display the time or to update time sensitive properties.
*
* @class ClockService
* @namespace EmberClock
*/
export default class ClockService extends Service {
disabled: boolean = false;

/**
* @property hour
*/
@tracked hour: number = 0;

/**
* @property minute
*/
@tracked minute: number = 0;

/**
* @property second
*/
@tracked second: number = 0;

/**
* Stores the next tick, so that it can be cancelled and the clock stopped.
* @property nextTick
* @private
*/
@tracked nextTick?: Timer;

/**
* @property isTicking
* @readonly
*/
get isTicking() {
return Boolean(this.nextTick);
}

/**
* Call `start()`
* @method constructor
*/
constructor(owner: Owner) {
super(owner);
this.start();
registerDestructor(this, () => this.stop());
}

/**
* Start the clock
*
* @method start
* @private
*/
start() {
this.tick();
}

/**
* Stop the clock
*
* @method stop
* @private
*/
stop() {
cancel(this.nextTick);
this.nextTick = undefined;
}

/**
* Set the time to the current time.
* @method setTime
* @private
*/
setTime() {
const now = new Date();
this.second = now.getSeconds();
this.minute = now.getMinutes();
this.hour = now.getHours();
}

/**
* Ticks the clock
* @method tick
* @private
*/
tick() {
this.setTime();
if (this.disabled) {
return;
}

this.nextTick = later(this, this.tick, Interval);
}
}

declare module '@ember/service' {
interface Registry {
clock: ClockService;
}
}
2 changes: 1 addition & 1 deletion ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

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

/*
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

module.exports = {
name: require('./package').name,

options: {
'ember-cli-babel': { enableTypeScriptTransform: true },
},
};
Loading

0 comments on commit 649a34d

Please sign in to comment.