Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add more functionality to the vue-devtools #31

Merged
merged 27 commits into from
Jul 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8208c85
feat: add more functionality to the vue-devtools
h2xd Jul 12, 2022
e51ab58
feat: add settings persistents
h2xd Jul 14, 2022
a9d3fe7
refactor: use the vue 3 approach
h2xd Jul 14, 2022
eb8efab
refactor: add statefull controller
h2xd Jul 14, 2022
37af5ad
refactor: move log function to a separate function
h2xd Jul 14, 2022
105a304
chore: add logs for storage events
h2xd Jul 14, 2022
e79c16f
fix: load stored items strait away
h2xd Jul 14, 2022
fe6c331
refactor: move settings view into separate module
h2xd Jul 14, 2022
035d6eb
chore: update homepage
h2xd Jul 14, 2022
15e110b
feat: enable auto save to localStorage
h2xd Jul 14, 2022
78afad0
fix: use the correct state value
h2xd Jul 14, 2022
3c0e4c0
refactor: reorganize package structure
h2xd Jul 14, 2022
26fd22c
feat: add disabled state handling
h2xd Jul 14, 2022
d035d53
refactor: rename to devtools with a lower t
h2xd Jul 14, 2022
21376e6
test: add no handler suite
h2xd Jul 14, 2022
519892f
chore: remove console log
h2xd Jul 14, 2022
a14640a
refactor: add main function
h2xd Jul 16, 2022
96458ac
refactor: modulize dev tools
h2xd Jul 16, 2022
f7beaa4
refactor: move main function
h2xd Jul 17, 2022
a22c377
style: add line break
h2xd Jul 17, 2022
e5aa40f
refactor: move scenario creation states
h2xd Jul 17, 2022
08a5a50
refactor: remove logs dependency
h2xd Jul 17, 2022
4fb6e5c
refactor: update package structure
h2xd Jul 17, 2022
3c0500b
refactor: remove emojis
h2xd Jul 17, 2022
05dc10f
docs: update highlighted lines
h2xd Jul 17, 2022
19cf29c
style: update file formatting
h2xd Jul 17, 2022
53a6ce8
chore: update monorepo lockfile
h2xd Jul 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/integrations/vue-devtools.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
Meanwhile please checkout the [hacky playground example](https://github.com/h2xd/exposition/blob/main/playground/src/main.ts).
:::

<<< ../playground/src/main.ts#vue-devtools{5-6}
<<< ../playground/src/main.ts#vue-devtools{5-13}
23 changes: 16 additions & 7 deletions packages/integrations/msw/functions/defineMSWIntegration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ beforeAll(() => {
rest.get('https://api.example.com/account', (_request, response, context) => {
switch (values.user) {
case 'authorized':
context.status(200)
return response(context.json({ name: 'Spanky 🐕' }))
case 'unauthorized':
context.status(401)
return response(context.json({}))
return response(context.status(401))
}
}),
]
Expand All @@ -45,9 +43,20 @@ it('should return an authorized code by default', async () => {
})

it('should return an 401 when set to unauthorized', async () => {
integration.updateValues({ user: 'unauthorized' }).then(async () => {
const response = await fetch('https://api.example.com/account')
integration.updateValues({ user: 'unauthorized' })

expect(response.status).toBe(401)
})
const response = await fetch('https://api.example.com/account')

expect(response.status).toBe(401)
})

it('should use no handler if explicitly called', async () => {
await integration.useNoHandlers()

try {
await fetch('/')
}
catch (error) {
expect(error).toBeDefined()
}
})
47 changes: 18 additions & 29 deletions packages/integrations/msw/functions/defineMSWIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,38 @@ export function defineMSWIntegration<T extends Exposition<ExpositionConfig>>(opt
return resetValues()
}

async function assignHandler(values: ExpositionValues<T>, delay = 10): Promise<void> {
return new Promise((resolve, reject) => {
try {
const handlerList = [...internalHandler, ...handlers].reduce((accumulator, handler) => {
return [
...accumulator,
...handler(values),
]
}, [] as Handler[])

msw.use(...handlerList)
function assignHandler(values: ExpositionValues<T>): void {
const handlerList = [...internalHandler, ...handlers].reduce((accumulator, handler) => {
return [
...accumulator,
...handler(values),
]
}, [] as Handler[])

msw.use(...handlerList)
}

/**
* Important! 🧦
* MSW seems to need some time to apply all handler.
* For that we mimic a `nextTick` functionality that exists in your
* favorite Frontend Framework.
* BUT, with a much simpler approach.
*/
setTimeout(resolve, delay)
}
catch (error) {
console.error(error)
reject(error)
}
})
function useNoHandlers(): void {
msw.resetHandlers()
msw.use()
}

function createHandler(handler: (values: ExpositionValues<T>) => Handler[]): void {
internalHandler.push(handler)
}

async function updateValues<TValues extends ExpositionValues<T>>(newValues: TValues): Promise<void> {
return assignHandler(newValues)
function updateValues<TValues extends ExpositionValues<T>>(newValues: TValues): void {
assignHandler(newValues)
}

async function resetValues(): Promise<void> {
return assignHandler(getExpositionValues(exposition))
function resetValues(): void {
assignHandler(getExpositionValues(exposition))
}

return {
createHandler,
updateValues,
useNoHandlers,
resetValues,
init,
}
Expand Down
4 changes: 1 addition & 3 deletions packages/integrations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
"sideEffects": false,
"dependencies": {
"@exposition/core": "workspace:*",
"@exposition/web": "workspace:*",
"debug": "^4.3.4"
"@exposition/web": "workspace:*"
},
"peerDependencies": {
"@vue/devtools-api": "^6.0.0-beta.14",
Expand All @@ -59,7 +58,6 @@
},
"devDependencies": {
"@rollup/plugin-json": "^4.1.0",
"@types/debug": "^4.1.7",
"@vue/devtools-api": "^6.2.0",
"cross-env": "^7.0.3",
"esbuild": "^0.12.9",
Expand Down
212 changes: 0 additions & 212 deletions packages/integrations/vue-devtools/functions/setupDevtools.ts

This file was deleted.

41 changes: 40 additions & 1 deletion packages/integrations/vue-devtools/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
export { setupDevtools } from './functions/setupDevtools'
import { setupDevtoolsPlugin } from '@vue/devtools-api'
import type { Exposition } from '@exposition/core'

import type { DevtoolsContext, OnUpdateHandler } from './src/@types/api'
import { defineDevtoolsSettingsState, defineExpositionState } from './src/states'
import { updateState } from './src/utils'
import { expositionLabel, id, stateType } from './src/config'
import { createInspectorViews, createSettingsViews, createTimelineViews } from './src/views'

export function setupDevtools<T extends Exposition<any>>(app: any, options: { exposition: T; onUpdate: OnUpdateHandler<T> }) {
const settings = defineDevtoolsSettingsState()
const state = defineExpositionState(options.exposition)

return setupDevtoolsPlugin({
id,
label: expositionLabel,
packageName: '@exposition/vue-devtools',
homepage: 'https://h2xd.github.io/exposition/integrations/vue-devtools.html',
componentStateTypes: [stateType],
app,
}, (api) => {
const context: DevtoolsContext<T> = {
api,
settings,
state,
onUpdate: options.onUpdate,
}

function main(): void {
createSettingsViews(context)
createTimelineViews(context)
createInspectorViews(context)

state.loadFromStore()
updateState(context)
}

main()
})
}
Loading