-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
116 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters