-
Notifications
You must be signed in to change notification settings - Fork 836
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Work for #2756: start implement reactivity
- Loading branch information
Showing
2 changed files
with
47 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,44 @@ | ||
import type { Question } from "survey-core"; | ||
import { ref, onBeforeMount } from "vue"; | ||
import type { Base } from "survey-core"; | ||
import { ref, defineComponent, type ComponentOptions } from "vue"; | ||
|
||
// by convention, composable function names start with "use" | ||
export function makeReactive(question: Question): void { | ||
onBeforeMount(() => { | ||
question.iteratePropertiesHash((propertiesHash: any, name: any) => { | ||
function makeReactive(surveyElement: Base) { | ||
surveyElement.iteratePropertiesHash((propertiesHash: any, name: any) => { | ||
// (<any>Vue.util).defineReactive(propertiesHash, name, propertiesHash[name]); | ||
propertiesHash[name] = ref(propertiesHash[name]); | ||
}); | ||
surveyElement.getPropertyValueCoreHandler = ( | ||
propertiesHash: any, | ||
name: string | ||
) => { | ||
// eslint-disable-next-line no-prototype-builtins | ||
if (!propertiesHash.hasOwnProperty(name)) { | ||
// (<any>Vue.util).defineReactive(propertiesHash, name, propertiesHash[name]); | ||
propertiesHash[name] = ref(propertiesHash[name]); | ||
}); | ||
question.getPropertyValueCoreHandler = ( | ||
propertiesHash: any, | ||
name: string | ||
) => { | ||
if (!propertiesHash.hasOwnProperty(name)) { | ||
// (<any>Vue.util).defineReactive(propertiesHash, name, propertiesHash[name]); | ||
propertiesHash[name] = ref(propertiesHash[name]); | ||
} | ||
return propertiesHash[name].value; | ||
}; | ||
question.setPropertyValueCoreHandler = ( | ||
propertiesHash: any, | ||
name: string, | ||
val: any | ||
) => { | ||
if (!propertiesHash.hasOwnProperty(name)) { | ||
propertiesHash[name] = ref(propertiesHash[name]); | ||
} else propertiesHash[name].value = val; | ||
}; | ||
}); | ||
} | ||
return propertiesHash[name].value; | ||
}; | ||
surveyElement.setPropertyValueCoreHandler = ( | ||
propertiesHash: any, | ||
name: string, | ||
val: any | ||
) => { | ||
// eslint-disable-next-line no-prototype-builtins | ||
if (!propertiesHash.hasOwnProperty(name)) { | ||
propertiesHash[name] = ref(propertiesHash[name]); | ||
} else propertiesHash[name].value = val; | ||
}; | ||
} | ||
// by convention, composable function names start with "use" | ||
|
||
export function defineSurveyComponent(componentDefinition: ComponentOptions) { | ||
const mounted = componentDefinition.mounted; | ||
componentDefinition.mounted = function () { | ||
if (typeof this.getModel === "function") { | ||
makeReactive(this.getModel()); | ||
} | ||
if (mounted) { | ||
mounted.call(this); | ||
} | ||
}; | ||
return defineComponent(componentDefinition); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters