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

refactor: <TodoSliceComponent /> #70

Merged
merged 1 commit into from
Mar 28, 2024
Merged

Conversation

lihbr
Copy link
Member

@lihbr lihbr commented Mar 27, 2024

Types of changes

  • Chore (a non-breaking change which is related to package maintenance)
  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

Mapped slices would cause the <TODOSliceComponent /> component to throw because of a different interface used by mapped slices (slice type being top level instead of nested under the slice property).

This standardizes the props given to <TODOSliceComponent /> so everything keeps working smoothly based on our Svelte implementation: https://github.com/prismicio/prismic-svelte/blob/master/src/SliceZone/SliceZone.svelte#L118-L128

I first explored adapting the <TODOSliceComponent /> to support different interfaces instead, but it resulted in messier code in my opinion:

const type = computed(() => {
// API slices
if (attrs.slice && typeof attrs.slice === "object") {
return "slice_type" in attrs.slice
? (attrs.slice as Record<string, unknown>).slice_type
: (attrs.slice as Record<string, unknown>).type;
}
// Mapped slices
return "slice_type" in attrs ? attrs.slice_type : attrs.type;
});
watchEffect(() => {
console.warn(
`[SliceZone] Could not find a component for Slice type "${type.value}"`,
attrs.slice || attrs,
);
});

Checklist:

  • My change requires an update to the official documentation.
  • All TSDoc comments are up-to-date and new ones have been added where necessary.
  • All new and existing tests are passing.

@lihbr lihbr merged commit 436834a into master Mar 28, 2024
16 checks passed
@lihbr lihbr deleted the refactor/todo-slice-component branch March 28, 2024 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant