experiments(dui3): adds mocked bindings and upgrades nuxt
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
|
||||
import { BaseBridge } from '~~/lib/bridge/base'
|
||||
|
||||
// Needs to be agreed between Frontend and Core
|
||||
export interface IBaseBinding {
|
||||
getAccounts: () => Promise<Account[]>
|
||||
@@ -57,3 +61,33 @@ export type ToastInfo = {
|
||||
details?: string
|
||||
type: 'info' | 'error' | 'warning'
|
||||
}
|
||||
|
||||
export class MockedBaseBinding extends BaseBridge {
|
||||
constructor() {
|
||||
super()
|
||||
}
|
||||
|
||||
public async getAccounts() {
|
||||
return []
|
||||
}
|
||||
|
||||
public async getSourceApplicationName() {
|
||||
return 'Mocks'
|
||||
}
|
||||
|
||||
public async getSourceApplicationVersion() {
|
||||
return '1'
|
||||
}
|
||||
|
||||
public async getDocumentInfo() {
|
||||
return {
|
||||
name: 'Mocked File',
|
||||
location: 'www',
|
||||
id: '42'
|
||||
}
|
||||
}
|
||||
|
||||
public async showDevTools() {
|
||||
console.log('Mocked bindings cannot do this')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
|
||||
import { BaseBridge } from '~~/lib/bridge/base'
|
||||
|
||||
/**
|
||||
* The name under which this binding will be registered.
|
||||
*/
|
||||
@@ -33,3 +37,28 @@ export type ComplexType = {
|
||||
id: string
|
||||
count: number
|
||||
}
|
||||
|
||||
export class MockedTestBinding extends BaseBridge {
|
||||
constructor() {
|
||||
super()
|
||||
}
|
||||
public async sayHi(name: string, count: number, sayHelloNotHi: boolean) {
|
||||
return `Hello from mocked bindings. Args: name = ${name}, count = ${count}, sayHelloNotHi = ${sayHelloNotHi.toString()}.`
|
||||
}
|
||||
|
||||
public async goAway() {
|
||||
return
|
||||
}
|
||||
|
||||
public async getComplexType() {
|
||||
return { id: 'wow', count: 42 }
|
||||
}
|
||||
|
||||
public async shouldThrow() {
|
||||
return
|
||||
}
|
||||
|
||||
public async triggerEvent(eventName: string) {
|
||||
return eventName
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@ export class GenericBridge extends BaseBridge {
|
||||
|
||||
try {
|
||||
availableMethodNames = await this.bridge.GetBindingsMethodNames()
|
||||
} catch {
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
"eslint-plugin-nuxt": "^4.0.0",
|
||||
"eslint-plugin-vue": "^9.5.1",
|
||||
"eslint-plugin-vuejs-accessibility": "^1.2.0",
|
||||
"nuxt": "^3.5.0",
|
||||
"nuxt": "^3.6.3",
|
||||
"postcss": "^8.4.18",
|
||||
"postcss-custom-properties": "^12.1.9",
|
||||
"postcss-html": "^1.5.0",
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
import { GenericBridge } from '~/lib/bridge/generic'
|
||||
import { IRawBridge } from '~/lib/bridge/definitions'
|
||||
|
||||
import { IBaseBinding } from '~/lib/bindings/definitions/baseBindings'
|
||||
import {
|
||||
IBaseBinding,
|
||||
MockedBaseBinding
|
||||
} from '~/lib/bindings/definitions/baseBindings'
|
||||
import { SketchupBridge } from '~/lib/bridge/sketchup'
|
||||
import { ITestBinding, ITestBindingKey } from '~/lib/bindings/definitions/testBindings'
|
||||
import {
|
||||
ITestBinding,
|
||||
ITestBindingKey,
|
||||
MockedTestBinding
|
||||
} from '~/lib/bindings/definitions/testBindings'
|
||||
|
||||
// Makes TS happy
|
||||
declare let globalThis: Record<string, unknown> & {
|
||||
@@ -19,11 +26,15 @@ declare let globalThis: Record<string, unknown> & {
|
||||
*/
|
||||
export default defineNuxtPlugin(async () => {
|
||||
// Registers some default test bindings.
|
||||
const testBindings = await tryHoistBinding<ITestBinding>(ITestBindingKey)
|
||||
const testBindings =
|
||||
(await tryHoistBinding<ITestBinding>(ITestBindingKey)) || new MockedTestBinding()
|
||||
|
||||
// Tries to register some non-existant bindings.
|
||||
const nonExistantBindings = await tryHoistBinding<IBaseBinding>('nonExistantBindings')
|
||||
|
||||
// Registers a set of default bindings.
|
||||
const baseBinding = await tryHoistBinding<IBaseBinding>('baseBinding')
|
||||
const baseBinding =
|
||||
(await tryHoistBinding<IBaseBinding>('baseBinding')) || new MockedBaseBinding()
|
||||
|
||||
const showDevTools = () => {
|
||||
baseBinding.showDevTools()
|
||||
|
||||
Reference in New Issue
Block a user