Skip to content
This repository has been archived by the owner on Sep 29, 2020. It is now read-only.

Typescriptify - Conversion to TypeScript. #133

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ end_of_line = lf
insert_final_newline = true
trim_trailing_whitespaces = true

# JavaScript
# JavaScript - and the like
#
# Two spaces seems to be the standard most common style, at least in
# Node.js (http://nodeguide.com/style.html#tabs-vs-spaces).
[*.js]
[*.{js,json,ts}]
indent_size = 2
indent_style = space
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lib/**/*.js
esm/**/*.js
test/babel/**/*.js
test/typescript/**/*.js
24 changes: 24 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
"env": {
"es6": true,
"node": true,
"mocha": true
},
"extends": "eslint:recommended",
parser: "babel-eslint",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"camelcase": "warn",
"no-unreachable": "warn",
"no-unused-vars": "warn",
"no-throw-literal": "warn",
"no-unused-expressions": "warn",
"no-console": "off",
"indent": ["error", 2],
"semi": ["error", "always"],
"space-before-function-paren": ["error", "never"]

}
};
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
node_modules
/lib/
/es/
/node_modules/
/built/
/esm/
/test/babel/
/test/typescript/
Copy link
Collaborator Author

@BurtHarris BurtHarris Jul 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests, from both transpilers, now build into these test subdirectories so that they can be compared.

*.log
27 changes: 23 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,31 @@
{
"type": "node",
"request": "launch",
"name": "Mocha Tests",
"name": "Gulp build.test.typescript",
"program": "${workspaceRoot}/node_modules/gulp/bin/gulp.js",
"args": [
"build.test.typescript"
]
},
{
"type": "node",
"request": "launch",
"name": "Mocha Tests (Babel)",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"args": [
"--no-timeouts",
"${workspaceRoot}/testBabel/**/*.spec.js",
"--debug"
]
},
{
"type": "node",
"request": "launch",
"name": "Mocha Tests (tsc)",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"args": [
"--compilers", "js:babel-core/register",
"--require", "babel-polyfill",
"${workspaceRoot}/test/**/*.spec.js",
"--no-timeouts",
"${workspaceRoot}/testtsc/**/*.spec.js",
"--debug"
]
}
Expand Down
27 changes: 27 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Place your settings in this file to overwrite default and user settings.
{

// Mocha: Options to run Mocha
"mocha.options": {},

// Mocha: Glob to search for test files
"mocha.files.glob": "test/babel/*.spec.js",

// Mocha: Globs to ignore when searching for test files
"mocha.files.ignore": [
"**/.git/**/*",
"**/node_modules/**/*"
],

// Mocha: Environment variables to run your tests
"mocha.env": {},

// Mocha: Options to pass to node executable
"mocha.node_options": [],

// Mocha: Subdirectory in the Workspace where run mocha from
"mocha.subfolder": "",

// Mocha: List of files to require before running mocha
"mocha.requires": []
}
25 changes: 17 additions & 8 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "tsc",
"isShellCommand": true,
"args": ["-w", "-p", "."],
"showOutput": "silent",
"isBackground": true,
"problemMatcher": "$tsc-watch"
}
"version": "2.0.0",
"tasks": [
{
"type": "gulp",
"task": "watch",
"isBackground": true,
"problemMatcher": [
"$gulp-tsc",
"$eslint-stylish"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
84 changes: 1 addition & 83 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# core-decorators.js [![Build Status](https://travis-ci.org/jayphelps/core-decorators.js.svg?branch=master)](https://travis-ci.org/jayphelps/core-decorators.js)
Library of [JavaScript stage-0 decorators](https://github.com/wycats/javascript-decorators) (aka ES2016/ES7 decorators [but that's not accurate](https://medium.com/@jayphelps/please-stop-referring-to-proposed-javascript-features-as-es7-cad29f9dcc4b)) inspired by languages that come with built-ins like @​override, @​deprecate, @​autobind, @​mixin and more. Popular with React/Angular, but is framework agnostic. Similar to [Annotations in Java](https://docs.oracle.com/javase/tutorial/java/annotations/predefined.html) but unlike Java annotations, decorators are functions which are applied at runtime.
Library of [JavaScript stage-0 decorators](https://github.com/wycats/javascript-decorators) (aka ES2016/ES7 decorators [but that's not accurate](https://medium.com/@jayphelps/please-stop-referring-to-proposed-javascript-features-as-es7-cad29f9dcc4b)) inspired by languages that come with built-ins like @​override, @​deprecate, @​autobind and more. Popular with React/Angular, but is framework agnostic. Similar to [Annotations in Java](https://docs.oracle.com/javase/tutorial/java/annotations/predefined.html) but unlike Java annotations, decorators are functions which are applied at runtime.

These are stage-0 decorators because while [the decorators spec has changed](http://tc39.github.io/proposal-decorators/) and is now stage-2, no transpiler has yet to implement these changes and until they do, this library won't either. Although the [TypeScript documentation](http://www.typescriptlang.org/docs/handbook/decorators.html) uses the phrase "Decorators are a stage 2 proposal for JavaScript" this is misleading because TypeScript still only implements the **stage-0** version of the spec, which is very incompatible with stage-2 (as of this writing). If you concretely find that a compiler (babel, TS, etc) implement stage-2+, please do link me to the appropriate release notes! :balloon:

Expand Down Expand Up @@ -44,14 +44,11 @@ core-decorators aims to provide decorators that are fundamental to JavaScript it
* [@suppressWarnings](#suppresswarnings)
* [@enumerable](#enumerable)
* [@override](#override)
* [@debounce](#debounce) :no_entry_sign: DEPRECATED
* [@throttle](#throttle) :no_entry_sign: DEPRECATED
* [@time](#time)
* [@profile](#profile)

##### For Classes
* [@autobind](#autobind)
* [@mixin](#mixin-alias-mixins) :no_entry_sign: DEPRECATED

## Helpers

Expand Down Expand Up @@ -189,52 +186,6 @@ person.facepalmHarder();
// See http://knowyourmeme.com/memes/facepalm for more details.
//
```

### @debounce :no_entry_sign: DEPRECATED

Creates a new debounced function which will be invoked after `wait` milliseconds since the time it was invoked. Default timeout is 300 ms.

Optional boolean second argument allows to trigger function on the leading instead of the trailing edge of the wait interval. Implementation is inspired by similar method from [UnderscoreJS](http://underscorejs.org/#debounce).

```js
import { debounce } from 'core-decorators';

class Editor {

content = '';

@debounce(500)
updateContent(content) {
this.content = content;
}
}
```

### @throttle :no_entry_sign: DEPRECATED

Creates a new throttled function which will be invoked in every `wait` milliseconds. Default timeout is 300 ms.

Second argument is optional options:

- `leading`: default to `true`, allows to trigger function on the leading.
- `trailing`: default to `true`, allows to trigger function on the trailing edge of the wait interval.

Implementation is inspired by similar method from [UnderscoreJS](http://underscorejs.org/#throttle).

```js
import { throttle } from 'core-decorators';

class Editor {

content = '';

@throttle(500, {leading: false})
updateContent(content) {
this.content = content;
}
}
```

### @suppressWarnings

Suppresses any JavaScript `console.warn()` call while the decorated function is called. (i.e. on the stack)
Expand Down Expand Up @@ -384,39 +335,6 @@ editor.hugeBuffer;
// createHugeBuffer() is not called again
```

### @mixin (alias: @mixins) :no_entry_sign: DEPRECATED

Mixes in all property descriptors from the provided Plain Old JavaScript Objects (aka POJOs) as arguments. Mixins are applied in the order they are passed, but do **not** override descriptors already on the class, including those inherited traditionally.

```js
import { mixin } from 'core-decorators';

const SingerMixin = {
sing(sound) {
alert(sound);
}
};

const FlyMixin = {
// All types of property descriptors are supported
get speed() {},
fly() {},
land() {}
};

@mixin(SingerMixin, FlyMixin)
class Bird {
singMatingCall() {
this.sing('tweet tweet');
}
}

var bird = new Bird();
bird.singMatingCall();
// alerts "tweet tweet"

```

### @time

Uses `console.time` and `console.timeEnd` to provide function timings with a unique label whose default prefix is `ClassName.method`. Supply a first argument to override the prefix:
Expand Down
8 changes: 3 additions & 5 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "core-decorators.js",
"description": "Library of ES2016 (ES7) JavaScript decorators inspired by languages that come with built-ins like @​override, @​deprecate, @​autobind, @​mixin and more! Works great with React/Angular/more!",
"description": "Library of ES2016 (ES7) JavaScript decorators inspired by languages that come with built-ins like @​override, @​deprecate, @​autobind and more! Works great with React/Angular/more!",
"version": "0.11.2",
"homepage": "https://github.com/jayphelps/core-decorators.js",
"authors": [
Expand All @@ -27,14 +27,12 @@
"autobind",
"react",
"angular",
"lodash",
"mixin",
"mixins"
"lodash"
],
"ignore": [
"**/.*",
"node_modules",
"test",
"scripts",
"scripts"
]
}
Loading