MCPcopy Create free account
hub / github.com/eclipsesource/jsonforms / useControl

Function useControl

packages/vue/src/jsonFormsCompositions.ts:178–228  ·  view source on GitHub ↗
(
  props: P,
  stateMap: (state: JsonFormsState, props: P) => R,
  dispatchMap?: (dispatch: Dispatch<CoreActions>) => D
)

Source from the content-addressed store, hash-verified

176// TODO fix @typescript-eslint/ban-types
177// eslint-disable-next-line @typescript-eslint/ban-types
178export function useControl<
179 R,
180 D,
181 P extends { schema: JsonSchema; uischema: UISchemaElement & Scopable }
182>(
183 props: P,
184 stateMap: (state: JsonFormsState, props: P) => R,
185 dispatchMap?: (dispatch: Dispatch<CoreActions>) => D
186) {
187 const jsonforms = useJsonForms();
188 const dispatch = useDispatch();
189
190 const id = ref<string | undefined>(undefined);
191 const control = computed(() => ({
192 ...props,
193 ...stateMap({ jsonforms }, props),
194 id: id.value,
195 }));
196
197 const dispatchMethods = dispatchMap?.(dispatch);
198
199 onBeforeMount(() => {
200 if (control.value.uischema.scope) {
201 id.value = Id.createId(control.value.uischema.scope);
202 }
203 });
204
205 watch(
206 () => props.schema,
207 (newSchema, prevSchem) => {
208 if (newSchema !== prevSchem && isControl(control.value.uischema)) {
209 if (id.value) {
210 Id.removeId(id.value);
211 }
212 id.value = Id.createId(control.value.uischema.scope);
213 }
214 }
215 );
216
217 onUnmounted(() => {
218 if (id.value) {
219 Id.removeId(id.value);
220 id.value = undefined;
221 }
222 });
223
224 return {
225 control: control,
226 ...dispatchMethods,
227 };
228}
229
230/**
231 * Provides generic bindings for 'Control' elements.

Callers 15

useJsonFormsControlFunction · 0.85
useJsonFormsEnumControlFunction · 0.85
useJsonFormsArrayControlFunction · 0.85
useJsonFormsAllOfControlFunction · 0.85
useJsonFormsAnyOfControlFunction · 0.85
useJsonFormsOneOfControlFunction · 0.85
useJsonFormsLayoutFunction · 0.85
useJsonFormsArrayLayoutFunction · 0.85

Calls 3

isControlFunction · 0.90
useDispatchFunction · 0.85
useJsonFormsFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…