From bf441f07a9064ad29a40829f5cbfe59efa788a96 Mon Sep 17 00:00:00 2001 From: Jiayu Liu Date: Fri, 13 Jul 2018 00:40:09 +0800 Subject: [PATCH] Add @tinajs/tina (#27191) - [x] Use a meaningful title for the pull request. Include the name of the package modified. - [x] Test the change in your own code. (Compile and run.) - [x] Add or edit tests to reflect the change. (Run with `npm test`.) - [x] Follow the advice from the [readme](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#make-a-pull-request). - [x] Avoid [common mistakes](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#common-mistakes). - [x] Run `npm run lint package-name` (or `tsc` if no `tslint.json` is present). - [x] The package does not already provide its own types, or cannot have its `.d.ts` files generated via `--declaration` - [x] If this is for an NPM package, match the name. If not, do not conflict with the name of an NPM package. - [x] Create it with `dts-gen --dt`, not by basing it on an existing project. - [x] `tslint.json` should be present, and `tsconfig.json` should have `noImplicitAny`, `noImplicitThis`, `strictNullChecks`, and `strictFunctionTypes` set to `true`. --- .github/CODEOWNERS | 1 + types/tinajs__tina/index.d.ts | 62 ++++++++++++++++++++++++ types/tinajs__tina/tinajs__tina-tests.ts | 57 ++++++++++++++++++++++ types/tinajs__tina/tsconfig.json | 19 ++++++++ types/tinajs__tina/tslint.json | 3 ++ 5 files changed, 142 insertions(+) create mode 100644 types/tinajs__tina/index.d.ts create mode 100644 types/tinajs__tina/tinajs__tina-tests.ts create mode 100644 types/tinajs__tina/tsconfig.json create mode 100644 types/tinajs__tina/tslint.json diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index fb6f7ba030..7d4afa76d3 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -4125,6 +4125,7 @@ /types/timelinejs3/ @MikeMatusz /types/timer-machine/ @dolanmiu /types/timezone-js/ @bonnici +/types/tinajs__tina/ @Jimexist /types/tinder/ @pingec /types/tiny-slider-react/ @screendriver /types/tinycolor2/ @M-Zuber @geertjansen @nvh diff --git a/types/tinajs__tina/index.d.ts b/types/tinajs__tina/index.d.ts new file mode 100644 index 0000000000..b29ad6bff9 --- /dev/null +++ b/types/tinajs__tina/index.d.ts @@ -0,0 +1,62 @@ +// Type definitions for @tinajs/tina 1.4 +// Project: https://github.com/tinajs/tina +// Definitions by: Jiayu Liu +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped/tinajs__tina +// TypeScript Version: 2.2 + +export function use(plugin: any): void; + +export interface ComponentProperties { + [key: string]: any; +} + +export interface ComponentLifecycles { + created: () => void; + attached: () => void; + ready: () => void; + moved: () => void; + detached: () => void; +} + +export interface ComponentDefinitions extends ComponentLifecycles { + properties: ComponentProperties; + data: { [key: string]: any }; + compute: (data: { [key: string]: any }) => { [key: string]: any }; + methods: { [name: string]: (this: Component) => any }; + mixins: Array>; +} + +export class Component { + static define(definitions: Partial): void; + static mixin(definitions: Partial): void; + setData(data: { [key: string]: any }): void; + data: { [key: string]: any }; +} + +export interface PageHooks { + beforeLoad: (this: Page) => void; + onLoad: (this: Page) => void; + onReady: (this: Page) => void; + onShow: (this: Page) => void; + onHide: (this: Page) => void; + onUnload: (this: Page) => void; +} + +export interface PageEvents { + onPullDownRefresh: (event: Page) => void; + onReachBottom: (event: Page) => void; + onShareAppMessage: (event: Page) => void; + onPageScroll: (event: Page) => void; +} + +export interface PageDefinitions + extends ComponentDefinitions, + PageEvents, + PageHooks { + mixins: Array>; +} + +export class Page extends Component { + static define(definitions: Partial): void; + static mixin(definitions: Partial): void; +} diff --git a/types/tinajs__tina/tinajs__tina-tests.ts b/types/tinajs__tina/tinajs__tina-tests.ts new file mode 100644 index 0000000000..3f3fad874f --- /dev/null +++ b/types/tinajs__tina/tinajs__tina-tests.ts @@ -0,0 +1,57 @@ +import { Page, Component } from "@tinajs/tina"; + +function sayHi() { + return "hi"; +} + +Page.mixin({ + onLoad: sayHi, + created: sayHi +}); + +Component.mixin({ + created: sayHi +}); + +Page.define({ + properties: { + content: String + } +}); + +Page.define({ + mixins: [ + { + methods: { + lol() { + return; + } + } + }, + { + methods: { + tiktok() { + return; + } + } + } + ], + data: { + count: 0 + }, + compute({ count }) { + return { countPlus1: count + 1 }; + }, + onLoad() { + this.data.count; + }, + methods: { + handleTapButton() { + this.data.count; + } + } +}); + +Component.define({ + data: {} +}); diff --git a/types/tinajs__tina/tsconfig.json b/types/tinajs__tina/tsconfig.json new file mode 100644 index 0000000000..8c2f008caa --- /dev/null +++ b/types/tinajs__tina/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "paths": { + "@tinajs/tina": ["tinajs__tina"] + } + }, + "files": ["index.d.ts", "tinajs__tina-tests.ts"] +} diff --git a/types/tinajs__tina/tslint.json b/types/tinajs__tina/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/tinajs__tina/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}