Skip to content
This repository has been archived by the owner on Dec 3, 2021. It is now read-only.

Commit

Permalink
Finish typing @vue/common
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Mühl committed Apr 8, 2021
1 parent 36b70b4 commit 74b7375
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 82 deletions.
12 changes: 1 addition & 11 deletions packages/awtrix/templates/core/apps/awtrix/0.0.1/backend.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
const { Yeelight } = require('yeelight-node')

module.exports = (BaseClass) => {
return class extends BaseClass {
register () {
const light = new Yeelight({ ip: '10.0.0.51', port: 55443 })

this.io.on('connect', (client) => {
client.on('toggle', (ctx) => {
light.toggle()
})
})
}
register () { }
}
}
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@awtrix/common",
"version": "0.1.3",
"version": "0.1.5",
"description": "awtrix",
"main": "dist/index.js",
"scripts": {
Expand Down
55 changes: 0 additions & 55 deletions packages/common/src/createFrontend.ts

This file was deleted.

61 changes: 61 additions & 0 deletions packages/common/src/defineComponent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {
defineComponent,
ComponentOptionsWithoutProps,
ComponentOptionsWithObjectProps,
ComponentOptionsWithArrayProps,
ComponentOptionsMixin,
ComputedOptions,
MethodOptions,
ComponentPropsOptions,
EmitsOptions
} from 'vue'
import FrontendApp from './FrontendApp'

export type GeneratorType = ((base: typeof FrontendApp) => ReturnType<typeof FrontendApp.extend>) & { options: any }

// Define function overloads for the extend function. These are necessary to
// allow for proper TypeScript typing and auto-completion. This basically
// copies the overloaded function types from the @vue/runtime-core package.
// The three possible argument types are:

/**
* Creates a new Vue component that inherits from the Awtrix HD FrontendApp.
*
* @param options
* @returns GeneratorType
*/
function extend<Props = {}, RawBindings = {}, D = {}, C extends ComputedOptions = {}, M extends MethodOptions = {}, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = typeof FrontendApp, E extends EmitsOptions = EmitsOptions, EE extends string = string>
(options: ComponentOptionsWithoutProps<Props, RawBindings, D, C, M, Mixin, Extends, E, EE>): GeneratorType

/**
* Creates a new Vue component that inherits from the Awtrix HD FrontendApp.
*
* @param options
* @returns GeneratorType
*/
function extend<PropNames extends string, RawBindings, D, C extends ComputedOptions = {}, M extends MethodOptions = {}, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = typeof FrontendApp, E extends EmitsOptions = Record<string, any>, EE extends string = string>
(options: ComponentOptionsWithArrayProps<PropNames, RawBindings, D, C, M, Mixin, Extends, E, EE>): GeneratorType

/**
* Creates a new Vue component that inherits from the Awtrix HD FrontendApp.
*
* @param options
* @returns GeneratorType
*/
function extend<PropsOptions extends Readonly<ComponentPropsOptions>, RawBindings, D, C extends ComputedOptions = {}, M extends MethodOptions = {}, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = typeof FrontendApp, E extends EmitsOptions = Record<string, any>, EE extends string = string>
(options: ComponentOptionsWithObjectProps<PropsOptions, RawBindings, D, C, M, Mixin, Extends, E, EE>): GeneratorType

// Finally the function implementation.
function extend(options: any): GeneratorType {
const generatorFunction = (base: typeof FrontendApp) => defineComponent({ ...options, extends: base })

// `vue-loader` creates a `render` function and attaches it to the exported function's
// `options` property. If the exported function is a Vue constructor that is fine. We
// are dealing with our custom generator function however, so we need to add the
// `options` property as well. We will then override the actual render function after
// loading the component in our frontend.
Object.assign(generatorFunction, { options: {} })
return generatorFunction as GeneratorType
}

export default extend
16 changes: 1 addition & 15 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
export { GeneratorType, default as createFrontend } from './createFrontend'
export { GeneratorType, default as defineComponent } from './defineComponent'
export { default as BackendApp } from './BackendApp'
export { default as FrontendApp } from './FrontendApp'
import { foobar } from './createFrontend'
export * as Types from './types'

foobar({
data () {
return {
nuddel: 'foa'
}
},

created () {
this.nuddel
this.lock()
}
})

0 comments on commit 74b7375

Please sign in to comment.