Skip to content

Commit

Permalink
Fix to ensure that a saved item with changed url doesn’t not auto-gen…
Browse files Browse the repository at this point in the history
…erate when reloaded.
  • Loading branch information
benosman committed Dec 15, 2021
1 parent d4c679c commit 1948e03
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions src/slug.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,24 @@ export default defineComponent({
const values = inject('values', ref<Record<string, any>>({}));
const isEditing = ref<Boolean>(props.autofocus);
const isTouched = ref<Boolean>(false);
const initialized = ref<Boolean>(false);
const prefix = computed(() => render(props.prefix || '', values.value));
const suffix = computed(() => render(props.suffix || '', values.value));
const presentedLink = computed(() => `${prefix.value}${props.value || props.placeholder || ''}${suffix.value}`);
const haveChange = computed(() => props.value && transform(render(props.template, values.value)) !== props.value);
const haveChange = computed(() => {
if (props.value) {
const result = transform(render(props.template, values.value)) !== props.value;
if (!initialized.value) {
initialized.value = true;
if (result) {
isTouched.value = true;
}
}
return result;
}
});
watch(values, (values: Record<string, any>) => {
// Reject manual touching.
if (isEditing.value || isTouched.value) return;
Expand Down Expand Up @@ -155,6 +167,7 @@ export default defineComponent({
}
function setByCurrentState() {
isTouched.value = false;
emitter(values.value);
}
Expand Down

0 comments on commit 1948e03

Please sign in to comment.