Skip to content

Commit

Permalink
chore: fix eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
Tidyzq committed Nov 16, 2023
1 parent 8995008 commit 9c11059
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 122 deletions.
5 changes: 3 additions & 2 deletions glass-easel-miniprogram-adapter/src/backend.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as glassEasel from 'glass-easel'
import { MiniProgramEnv, StyleIsolation } from '.'
import { CodeSpace } from './space'
import { type MiniProgramEnv } from './env'
import { type CodeSpace } from './space'
import { StyleIsolation } from './types'

/**
* A backend context that has been associated to an environment
Expand Down
6 changes: 3 additions & 3 deletions glass-easel-miniprogram-adapter/src/behavior.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as glassEasel from 'glass-easel'
import { GeneralComponentDefinition, utils as typeUtils } from './types'
import { GeneralComponent } from './component'
import type * as glassEasel from 'glass-easel'
import { type GeneralComponentDefinition, type utils as typeUtils } from './types'
import { type GeneralComponent } from './component'

type DataList = typeUtils.DataList
type PropertyList = typeUtils.PropertyList
Expand Down
4 changes: 2 additions & 2 deletions glass-easel-miniprogram-adapter/src/component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as glassEasel from 'glass-easel'
import { utils as typeUtils } from './types'
import { ComponentType, GeneralBehavior, TraitBehavior } from './behavior'
import { type utils as typeUtils } from './types'
import { type ComponentType, type GeneralBehavior, type TraitBehavior } from './behavior'
import { SelectorQuery } from './selector_query'
import { IntersectionObserver } from './intersection'
import { MediaQueryObserver } from './media_query'
Expand Down
73 changes: 73 additions & 0 deletions glass-easel-miniprogram-adapter/src/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import * as glassEasel from 'glass-easel'
import { AssociatedBackend } from './backend'
import { CodeSpace } from './space'

/**
* A mini-program API environment
*
* Each environment manages multiple backend contexts.
* However, a backend context should be exclusively managed by a single environment
* (to avoid `StyleScopeId` confliction).
* It is able to create multiple `CodeSpace` within the environment.
*/
export class MiniProgramEnv {
private codeSpaceMap: { [id: string]: CodeSpace }
private globalCodeSpace: CodeSpace

/**
* Create an empty mini-program API environment
*/
constructor() {
this.codeSpaceMap = Object.create(null) as { [id: string]: CodeSpace }
this.globalCodeSpace = new CodeSpace(this, false, {})
}

/**
* Get a global code space in which global components can be defined
*
* External glass-easel based components can be defined in this code space.
* All global components should be defined before any other `CodeSpace` created!
*/
getGlobalCodeSpace(): CodeSpace {
return this.globalCodeSpace
}

/**
* Associate a backend context
*
* If `backendContext` is not given, the DOM-based backend is used
* (causes failure if running outside browsers).
* The backend context SHOULD NOT be associated by other environments!
*/
associateBackend(backendContent?: glassEasel.GeneralBackendContext): AssociatedBackend {
const ctx = backendContent ?? new glassEasel.CurrentWindowBackendContext()
return new AssociatedBackend(this, ctx)
}

/**
* Create a component space that can manage WXML, WXSS, JS and static JSON config files
*
* The space can be specified as a *main* space.
* This makes some features available:
* * the `app.wxss` will be used as a style sheet for all root components in the space;
* * the `StyleIsolation.Shared` is accepted for components in the space.
* Non-main spaces usually act as plugins.
* `publicComponents` is a map for specifying a map of aliases and component paths.
*/
createCodeSpace(
id: string,
isMainSpace: boolean,
publicComponents = Object.create(null) as { [alias: string]: string },
): CodeSpace {
const cs = new CodeSpace(this, isMainSpace, publicComponents, this.globalCodeSpace)
this.codeSpaceMap[id] = cs
return cs
}

/**
* Get a component space by the `id` specified when created
*/
getCodeSpace(id: string): CodeSpace | undefined {
return this.codeSpaceMap[id]
}
}
80 changes: 3 additions & 77 deletions glass-easel-miniprogram-adapter/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,80 +1,6 @@
import * as glassEasel from 'glass-easel'
import { AssociatedBackend } from './backend'
import { CodeSpace } from './space'

export * as glassEasel from 'glass-easel'
export * as types from './types'
export { StyleIsolation } from './types'
export * from './space'
export { AssociatedBackend, Root } from './backend'
export * as component from './component'

/**
* A mini-program API environment
*
* Each environment manages multiple backend contexts.
* However, a backend context should be exclusively managed by a single environment
* (to avoid `StyleScopeId` confliction).
* It is able to create multiple `CodeSpace` within the environment.
*/
export class MiniProgramEnv {
private codeSpaceMap: { [id: string]: CodeSpace }
private globalCodeSpace: CodeSpace

/**
* Create an empty mini-program API environment
*/
constructor() {
this.codeSpaceMap = Object.create(null) as { [id: string]: CodeSpace }
this.globalCodeSpace = new CodeSpace(this, false, {})
}

/**
* Get a global code space in which global components can be defined
*
* External glass-easel based components can be defined in this code space.
* All global components should be defined before any other `CodeSpace` created!
*/
getGlobalCodeSpace(): CodeSpace {
return this.globalCodeSpace
}

/**
* Associate a backend context
*
* If `backendContext` is not given, the DOM-based backend is used
* (causes failure if running outside browsers).
* The backend context SHOULD NOT be associated by other environments!
*/
associateBackend(backendContent?: glassEasel.GeneralBackendContext): AssociatedBackend {
const ctx = backendContent ?? new glassEasel.CurrentWindowBackendContext()
return new AssociatedBackend(this, ctx)
}

/**
* Create a component space that can manage WXML, WXSS, JS and static JSON config files
*
* The space can be specified as a *main* space.
* This makes some features available:
* * the `app.wxss` will be used as a style sheet for all root components in the space;
* * the `StyleIsolation.Shared` is accepted for components in the space.
* Non-main spaces usually act as plugins.
* `publicComponents` is a map for specifying a map of aliases and component paths.
*/
createCodeSpace(
id: string,
isMainSpace: boolean,
publicComponents = Object.create(null) as { [alias: string]: string },
): CodeSpace {
const cs = new CodeSpace(this, isMainSpace, publicComponents, this.globalCodeSpace)
this.codeSpaceMap[id] = cs
return cs
}

/**
* Get a component space by the `id` specified when created
*/
getCodeSpace(id: string): CodeSpace | undefined {
return this.codeSpaceMap[id]
}
}
export { MiniProgramEnv } from './env'
export * from './space'
export * as types from './types'
4 changes: 2 additions & 2 deletions glass-easel-miniprogram-adapter/src/intersection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as glassEasel from 'glass-easel'
import { GeneralComponent } from './component'
import type * as glassEasel from 'glass-easel'
import { type GeneralComponent } from './component'

export type IntersectionObserverMargins = {
left: number
Expand Down
4 changes: 2 additions & 2 deletions glass-easel-miniprogram-adapter/src/media_query.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as glassEasel from 'glass-easel'
import { GeneralComponent } from './component'
import type * as glassEasel from 'glass-easel'
import { type GeneralComponent } from './component'

export class MediaQueryObserver {
private _$comp: GeneralComponent
Expand Down
2 changes: 1 addition & 1 deletion glass-easel-miniprogram-adapter/src/selector_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ export class SelectorQuery {
],
() => {
if (fields.properties) {
if (elem instanceof glassEasel.Component) {
if (glassEasel.Component.isComponent(elem)) {
fields.properties.forEach((propName) => {
if (glassEasel.Component.hasProperty(elem, propName)) {
const ds = elem.getComponentOptions().propertyPassingDeepCopy
Expand Down
30 changes: 15 additions & 15 deletions glass-easel-miniprogram-adapter/src/space.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
/* eslint-disable @typescript-eslint/no-unsafe-return */

import * as glassEasel from 'glass-easel'
import { MiniProgramEnv } from '.'
import {
ComponentStaticConfig,
ComponentDefinitionOptions,
StyleIsolation,
BehaviorDefinition,
ComponentDefinition,
PageDefinition,
utils as typeUtils,
} from './types'
import { guid } from './utils'
import {
Behavior,
ComponentType,
DefinitionFilter,
GeneralBehavior,
TraitBehavior,
type DefinitionFilter,
type GeneralBehavior,
} from './behavior'
import { AllData, Component, ComponentProto, GeneralComponent } from './component'
import { ComponentProto, type AllData, type Component, type GeneralComponent } from './component'
import { type MiniProgramEnv } from './env'
import {
StyleIsolation,
type BehaviorDefinition,
type ComponentDefinition,
type ComponentDefinitionOptions,
type ComponentStaticConfig,
type PageDefinition,
type utils as typeUtils,
} from './types'
import { guid } from './utils'

// The page constructor
export interface PageConstructor {
Expand Down Expand Up @@ -1123,7 +1123,7 @@ export class BehaviorBuilder<
TNewData extends DataList = Empty,
TNewProperty extends PropertyList = Empty,
TNewMethod extends MethodList = Empty,
TNewComponentExport = never
TNewComponentExport = never,
>(
def: BehaviorDefinition<TNewData, TNewProperty, TNewMethod, TNewComponentExport> &
ThisType<
Expand Down
6 changes: 3 additions & 3 deletions glass-easel-miniprogram-adapter/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DeepCopyKind, typeUtils as utils } from 'glass-easel'
import type { DefinitionFilter, GeneralBehavior, Behavior } from './behavior'
import { GeneralComponent } from './component'
import { type DeepCopyKind, type typeUtils as utils } from 'glass-easel'
import type { Behavior, DefinitionFilter, GeneralBehavior } from './behavior'
import { type GeneralComponent } from './component'

export { typeUtils as utils } from 'glass-easel'

Expand Down
2 changes: 1 addition & 1 deletion glass-easel-miniprogram-adapter/tests/base/env.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-new-func */
/* eslint-disable @typescript-eslint/no-implied-eval */

import * as glassEasel from 'glass-easel'
import type * as glassEasel from 'glass-easel'
import { TmplGroup } from 'glass-easel-template-compiler'

export const tmpl = (src: string): glassEasel.template.ComponentTemplate => {
Expand Down
22 changes: 8 additions & 14 deletions glass-easel-miniprogram-adapter/tests/space.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import * as glassEasel from 'glass-easel'
import { type BehaviorConstructor, type ComponentConstructor, MiniProgramEnv, types } from '../src'
import { tmpl } from './base/env'
import {
MiniProgramEnv,
StyleIsolation,
BehaviorConstructor,
ComponentConstructor,
types,
} from '../src'

const domHtml = (elem: glassEasel.Element): string => {
const domElem = elem.getBackendElement() as unknown as Element
Expand Down Expand Up @@ -430,7 +424,7 @@ describe('define', () => {
codeSpace.addStyleSheet('child/comp', 'empty-style-sheet', 'child-comp')
codeSpace.addComponentStaticConfig('child/comp', {
component: true,
styleIsolation: StyleIsolation.Shared,
styleIsolation: types.StyleIsolation.Shared,
})
codeSpace.addCompiledTemplate(
'child/comp',
Expand All @@ -451,7 +445,7 @@ describe('define', () => {
usingComponents: {
child: '/child/comp',
},
styleIsolation: StyleIsolation.PageShared,
styleIsolation: types.StyleIsolation.PageShared,
})
codeSpace.addCompiledTemplate(
'path/to/comp',
Expand All @@ -478,7 +472,7 @@ describe('define', () => {
codeSpace.addStyleSheet('child/comp', 'empty-style-sheet', 'child-comp')
codeSpace.addComponentStaticConfig('child/comp', {
component: true,
styleIsolation: StyleIsolation.ApplyShared,
styleIsolation: types.StyleIsolation.ApplyShared,
})
codeSpace.addCompiledTemplate(
'child/comp',
Expand All @@ -499,7 +493,7 @@ describe('define', () => {
usingComponents: {
child: '/child/comp',
},
styleIsolation: StyleIsolation.PageApplyShared,
styleIsolation: types.StyleIsolation.PageApplyShared,
})
codeSpace.addCompiledTemplate(
'path/to/comp',
Expand Down Expand Up @@ -528,7 +522,7 @@ describe('define', () => {
codeSpace.addStyleSheet('child/comp', 'empty-style-sheet', 'child-comp')
codeSpace.addComponentStaticConfig('child/comp', {
component: true,
styleIsolation: StyleIsolation.Isolated,
styleIsolation: types.StyleIsolation.Isolated,
})
codeSpace.addCompiledTemplate(
'child/comp',
Expand All @@ -549,7 +543,7 @@ describe('define', () => {
usingComponents: {
child: '/child/comp',
},
styleIsolation: StyleIsolation.PageIsolated,
styleIsolation: types.StyleIsolation.PageIsolated,
})
codeSpace.addCompiledTemplate(
'path/to/comp',
Expand Down Expand Up @@ -627,7 +621,7 @@ describe('define', () => {
usingComponents: {
child: '/child/comp',
},
styleIsolation: StyleIsolation.PageIsolated,
styleIsolation: types.StyleIsolation.PageIsolated,
})
codeSpace.addCompiledTemplate(
'path/to/comp',
Expand Down

0 comments on commit 9c11059

Please sign in to comment.