Skip to content

Commit 0f53c70

Browse files
fix: better structuring
1 parent f6a8780 commit 0f53c70

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

website/src/components/Playground.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const {
1717
state,
1818
mode,
1919
lang,
20+
reset,
2021
// source code
2122
source,
2223
// config
@@ -95,7 +96,7 @@ let codeMode = shallowRef('code')
9596
<template #addon>
9697
<div class="action-bar">
9798
<SelectLang v-model="lang"/>
98-
<ResetConfig v-model="state" />
99+
<ResetConfig @reset="reset" />
99100
</div>
100101
</template>
101102
</Tabs>

website/src/components/ResetConfig.vue

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
<script lang="ts" setup>
22
import IconReset from '../icons/Reset.vue'
33
4-
import type { State } from './astGrep/state'
5-
import { config, query, rewrite } from './astGrep/state'
6-
7-
const state = defineModel<State>({
8-
required: true,
9-
})
10-
11-
const onReset = () => {
12-
state.value.config = config
13-
state.value.query = query
14-
state.value.rewrite = rewrite
15-
}
4+
const emits = defineEmits<{
5+
reset: () => void
6+
}>()
167
</script>
178

189
<template>
19-
<button class="reset" title="Reset your config" @click="onReset">
10+
<button class="reset" title="Reset your config" @click="emits('reset')">
2011
<IconReset />
2112
</button>
2213
</template>

website/src/components/astGrep/state.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ if (true) {
5454
console.debug('matched by YAML')
5555
}`
5656

57-
export const query = 'console.log($MATCH)'
58-
export const rewrite = 'logger.log($MATCH)'
59-
export const config = `
57+
const query = 'console.log($MATCH)'
58+
const rewrite = 'logger.log($MATCH)'
59+
const config = `
6060
# YAML Rule is more powerful!
6161
# https://ast-grep.github.io/guide/rule-config.html#rule
6262
rule:
@@ -108,6 +108,17 @@ function storeStateInLocalStorage(state: State) {
108108
}
109109
}
110110

111+
function resetState(state: ShallowReactive<State>) {
112+
state.mode = Mode.Patch
113+
state.query = query
114+
state.rewrite = rewrite
115+
state.config = config
116+
state.source = source
117+
state.strictness = 'smart'
118+
state.selector = ''
119+
state.lang = 'javascript'
120+
}
121+
111122
export const astGrepStateKey = Symbol.for('ast-grep-state') as InjectionKey<ToRefs<ShallowReactive<State>>>
112123

113124
export function useSgState() {
@@ -119,6 +130,7 @@ export function useSgState() {
119130
}, { deep: true })
120131
return {
121132
state,
133+
reset: () => resetState(state),
122134
...refs,
123135
}
124-
}
136+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy