-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Reactivity mechanism prototype
- Loading branch information
Showing
17 changed files
with
1,971 additions
and
255 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
.idea | ||
.vscode | ||
node_modules | ||
src | ||
|
||
.gitignore | ||
.npmrc | ||
eslint.config.mjs | ||
eslint.config.js | ||
tsconfig.json | ||
yarn.lock |
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,45 @@ | ||
import globals from 'globals' | ||
|
||
import pluginJs from '@eslint/js' | ||
import pluginTs from 'typescript-eslint' | ||
import pluginVue from 'eslint-plugin-vue' | ||
|
||
export default [ | ||
{ files: ['**/*.{js,mjs,cjs,ts,vue}'] }, | ||
{ | ||
languageOptions: { | ||
globals: { | ||
...globals.browser, | ||
...globals.node, | ||
}, | ||
}, | ||
}, | ||
pluginJs.configs.recommended, | ||
...pluginTs.configs.recommended, | ||
...pluginVue.configs['flat/essential'], | ||
{ | ||
files: ['**/*.vue'], | ||
languageOptions: { | ||
parserOptions: { parser: pluginTs.parser }, | ||
}, | ||
}, | ||
{ | ||
rules: { | ||
'comma-dangle': ['error', { | ||
arrays: 'always-multiline', | ||
exports: 'always-multiline', | ||
functions: 'never', | ||
imports: 'always-multiline', | ||
objects: 'always-multiline', | ||
}], | ||
'indent': ['error', 2, { | ||
'ignoreComments': true, | ||
'SwitchCase': 1, | ||
}], | ||
'quotes': ['error', 'single'], | ||
'semi': ['error', 'never'], | ||
|
||
'@typescript-eslint/naming-convention': 'off', | ||
}, | ||
}, | ||
] |
This file was deleted.
Oops, something went wrong.
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,52 @@ | ||
import type { | ||
CreateEndpointOptions, | ||
MessageEndpoint, | ||
} from '@remote-ui/rpc' | ||
|
||
import type { | ||
Endpoint, | ||
EndpointApi, | ||
} from '~types/endpoint' | ||
|
||
import { | ||
createEndpoint, | ||
release, | ||
retain, | ||
} from '@remote-ui/rpc' | ||
|
||
export const createWidgetEndpoint = <API extends EndpointApi, T>( | ||
api: API, | ||
messenger: MessageEndpoint, | ||
options: CreateEndpointOptions<T> | ||
): Endpoint<API> => { | ||
const endpoint = createEndpoint(messenger, options) | ||
|
||
let onRelease = () => {} | ||
|
||
endpoint.expose({ | ||
async run (channel, placement, methods) { | ||
retain(channel) | ||
retain(methods) | ||
|
||
onRelease = () => { | ||
release(channel) | ||
release(methods) | ||
} | ||
|
||
await api.run(channel, placement, methods) | ||
}, | ||
|
||
release () { | ||
api.release() | ||
|
||
onRelease() | ||
onRelease = () => {} | ||
}, | ||
|
||
on (event, payload) { | ||
api.on(event, payload) | ||
}, | ||
} as API) | ||
|
||
return endpoint | ||
} |
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,52 @@ | ||
import type { | ||
FieldSchema, | ||
EventSchema, | ||
RemoteMethods, | ||
} from '~types/context/order' | ||
|
||
import { defineStore } from 'pinia' | ||
|
||
export type State = FieldSchema & { | ||
api: RemoteMethods | null; | ||
} | ||
|
||
export const useStore = defineStore('order', { | ||
state (): State { | ||
return { | ||
api: null, | ||
'customer.email': null, | ||
'customer.phone': null, | ||
'delivery.address': null, | ||
} | ||
}, | ||
|
||
actions: { | ||
async initialize (api: RemoteMethods) { | ||
this.api = api | ||
|
||
await api.get('~').then(state => { | ||
this['customer.email'] = state['customer.email'] | ||
this['customer.phone'] = state['customer.phone'] | ||
this['delivery.address'] = state['delivery.address'] | ||
}) | ||
}, | ||
|
||
set <F extends keyof FieldSchema> (name: F, value: FieldSchema[F], synchronize = true) { | ||
this[name] = value | ||
if (synchronize) { | ||
this.api?.set(name, value) | ||
} | ||
}, | ||
|
||
on <K extends keyof EventSchema>(event: K, payload: EventSchema[K]) { | ||
switch (event) { | ||
case 'change:customer.email': | ||
return this.set('customer.email', payload as string | null, false) | ||
case 'change:customer.phone': | ||
return this.set('customer.phone', payload as string | null, false) | ||
case 'change:delivery.address': | ||
return this.set('delivery.address', payload as string | null, false) | ||
} | ||
}, | ||
}, | ||
}) |
Oops, something went wrong.