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

[stonecrop] setup stonecrop when component has been mounted #238

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@stonecrop/nuxt",
"comment": "setup stonecrop when component has been mounted",
"type": "patch"
}
],
"packageName": "@stonecrop/nuxt"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@stonecrop/stonecrop",
"comment": "setup stonecrop when component has been mounted",
"type": "patch"
}
],
"packageName": "@stonecrop/stonecrop"
}
2 changes: 1 addition & 1 deletion common/config/rush/version-policies.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"definitionName": "lockStepVersion",
"policyName": "stonecrop",
"version": "0.4.0",
"nextBump": "minor"
"nextBump": "patch"
}
// {
// /**
Expand Down
3 changes: 1 addition & 2 deletions common/reviews/api/stonecrop.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ export const Stonecrop: Plugin_2;

// @public
export type StonecropReturn = {
stonecrop: Ref<Stonecrop_2>;
isReady: Ref<boolean>;
stonecrop: Ref<Stonecrop_2 | undefined>;
};

// @public
Expand Down
3 changes: 1 addition & 2 deletions docs/stonecrop/stonecrop.stonecropreturn.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Stonecrop composable return type

```typescript
export type StonecropReturn = {
stonecrop: Ref<Stonecrop>;
isReady: Ref<boolean>;
stonecrop: Ref<Stonecrop | undefined>;
};
```
6 changes: 1 addition & 5 deletions nuxt/src/runtime/layouts/StonecropHome.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
<template>
<div>Stonecrop Home</div>

<div v-if="isReady">
<p>Stonecrop is ready!</p>
</div>
<pre>{{ stonecrop }}</pre>
</template>

<script setup lang="ts">
import { useStonecrop } from '@stonecrop/stonecrop'

const { stonecrop, isReady } = useStonecrop()
const { stonecrop } = useStonecrop()
</script>
37 changes: 17 additions & 20 deletions stonecrop/src/composable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { inject, onBeforeMount, Ref, ref } from 'vue'
import { inject, onMounted, Ref, ref } from 'vue'

import Registry from './registry'
import { Stonecrop } from './stonecrop'
Expand All @@ -9,8 +9,7 @@ import { useDataStore } from './stores/data'
* @public
*/
export type StonecropReturn = {
stonecrop: Ref<Stonecrop>
isReady: Ref<boolean>
stonecrop: Ref<Stonecrop | undefined>
}

/**
Expand All @@ -21,22 +20,23 @@ export type StonecropReturn = {
* @public
*/
export function useStonecrop(registry?: Registry): StonecropReturn {
if (!registry) {
registry = inject<Registry>('$registry')
}
const stonecrop = ref<Stonecrop>()

let store: ReturnType<typeof useDataStore>
try {
store = useDataStore()
} catch (e) {
throw new Error('Please enable the Stonecrop plugin before using the Stonecrop composable')
}
onMounted(async () => {
if (!registry) {
registry = inject<Registry>('$registry')
}

let store: ReturnType<typeof useDataStore>
try {
store = useDataStore()
} catch (e) {
throw new Error('Please enable the Stonecrop plugin before using the Stonecrop composable')
}

// @ts-expect-error TODO: handle empty registry passed to Stonecrop
const stonecrop = ref(new Stonecrop(registry, store))
const isReady = ref(false)
// @ts-expect-error TODO: handle empty registry passed to Stonecrop
stonecrop.value = new Stonecrop(registry, store)

onBeforeMount(async () => {
if (!registry || !registry.router) return

const route = registry.router.currentRoute.value
Expand Down Expand Up @@ -64,10 +64,7 @@ export function useStonecrop(registry?: Registry): StonecropReturn {

stonecrop.value.runAction(doctype, 'LOAD', recordId ? [recordId] : undefined)
}

isReady.value = true
})

// @ts-expect-error TODO: fix the type mismatch
return { stonecrop, isReady }
return { stonecrop }
}
Loading