decord/source/3903_useViewModelInstance.js

193 lines
6.2 KiB
JavaScript
Raw Normal View History

2026-07-25 08:10:48 +00:00
// Module ID: 3903
// Function ID: 32294
2026-07-20 16:05:17 +00:00
// Name: useViewModelInstance
2026-07-25 08:10:48 +00:00
// Dependencies: [31, 3892, 3896, 3884]
2026-07-20 16:05:17 +00:00
// Exports: useViewModelInstance
2026-07-25 08:10:48 +00:00
// Module 3903 (useViewModelInstance)
2026-07-23 10:11:24 +00:00
import result from "result";
let closure_2;
let closure_3;
({ useMemo: closure_2, useRef: closure_3 } = result);
2026-07-20 16:05:17 +00:00
export const useViewModelInstance = function useViewModelInstance(arg0, instanceName) {
2026-07-23 10:11:24 +00:00
const _require = arg0;
2026-07-20 16:05:17 +00:00
instanceName = undefined;
if (null != instanceName) {
instanceName = instanceName.instanceName;
}
let name;
if (null != instanceName) {
name = instanceName.name;
}
if (null != instanceName) {
name = instanceName;
}
let artboardName;
if (null != instanceName) {
artboardName = instanceName.artboardName;
}
let viewModelName;
if (null != instanceName) {
viewModelName = instanceName.viewModelName;
}
let useNew;
if (null != instanceName) {
useNew = instanceName.useNew;
}
2026-07-23 10:11:24 +00:00
let closure_4 = tmp6;
2026-07-20 16:05:17 +00:00
let required;
if (null != instanceName) {
required = instanceName.required;
}
let onInit;
if (null != instanceName) {
onInit = instanceName.onInit;
}
const tmp10 = viewModelName(onInit);
2026-07-23 10:11:24 +00:00
let closure_5 = tmp10;
2026-07-20 16:05:17 +00:00
tmp10.current = onInit;
2026-07-23 10:11:24 +00:00
let obj = _require(name[2]);
const items = [arg0, name, artboardName, viewModelName, null != useNew && useNew];
2026-07-20 16:05:17 +00:00
const disposableMemo = obj.useDisposableMemo(() => {
2026-07-23 10:11:24 +00:00
const tmp = (function createInstance(closure_0, name, artboardName, viewModelName, closure_4) {
if (closure_0) {
let tmp2 = null != closure_0;
2026-07-20 16:05:17 +00:00
if (tmp2) {
2026-07-23 10:11:24 +00:00
tmp2 = "getViewModelInstance" in closure_0;
2026-07-20 16:05:17 +00:00
}
if (tmp2) {
2026-07-23 10:11:24 +00:00
const viewModelInstance = closure_0.getViewModelInstance();
2026-07-20 16:05:17 +00:00
let obj = {};
let tmp17 = null;
if (null != viewModelInstance) {
tmp17 = viewModelInstance;
}
obj.instance = tmp17;
obj.needsDispose = false;
return obj;
} else {
2026-07-23 10:11:24 +00:00
let tmp3 = null != closure_0;
2026-07-20 16:05:17 +00:00
if (tmp3) {
2026-07-23 10:11:24 +00:00
tmp3 = "defaultArtboardViewModel" in closure_0;
2026-07-20 16:05:17 +00:00
}
if (tmp3) {
if (viewModelName) {
2026-07-23 10:11:24 +00:00
let viewModelByNameResult = closure_0.viewModelByName(viewModelName);
2026-07-20 16:05:17 +00:00
if (!viewModelByNameResult) {
2026-07-23 10:11:24 +00:00
obj = { instance: null, needsDispose: false };
2026-07-20 16:05:17 +00:00
const _HermesInternal3 = HermesInternal;
obj.error = "ViewModel '" + viewModelName + "' not found";
return obj;
}
} else {
let ArtboardByNameResult;
if (artboardName) {
2026-07-23 10:11:24 +00:00
let obj3 = callback(name[1]);
2026-07-20 16:05:17 +00:00
ArtboardByNameResult = obj3.ArtboardByName(artboardName);
}
2026-07-23 10:11:24 +00:00
viewModelByNameResult = closure_0.defaultArtboardViewModel(ArtboardByNameResult);
2026-07-20 16:05:17 +00:00
if (!viewModelByNameResult) {
if (artboardName) {
2026-07-23 10:11:24 +00:00
const obj1 = { instance: null, needsDispose: false };
2026-07-20 16:05:17 +00:00
const _HermesInternal2 = HermesInternal;
obj1.error = "Artboard '" + artboardName + "' not found or has no ViewModel";
let obj2 = obj1;
} else {
2026-07-23 10:11:24 +00:00
obj2 = { instance: null, needsDispose: false };
2026-07-20 16:05:17 +00:00
}
return obj2;
}
}
if (name) {
let instanceByName = viewModelByNameResult.createInstanceByName(name);
} else {
instanceByName = viewModelByNameResult.createDefaultInstance();
}
if (!instanceByName) {
if (name) {
2026-07-23 10:11:24 +00:00
obj3 = { instance: null, needsDispose: false };
2026-07-20 16:05:17 +00:00
const _HermesInternal4 = HermesInternal;
obj3.error = "ViewModel instance '" + name + "' not found";
}
return obj3;
}
const obj4 = {};
let tmp15 = null;
if (null != instanceByName) {
tmp15 = instanceByName;
}
obj4.instance = tmp15;
obj4.needsDispose = true;
obj3 = obj4;
} else {
if (name) {
2026-07-23 10:11:24 +00:00
let instanceByName1 = closure_0.createInstanceByName(name);
2026-07-20 16:05:17 +00:00
if (!instanceByName1) {
2026-07-23 10:11:24 +00:00
const obj5 = { instance: null, needsDispose: false };
2026-07-20 16:05:17 +00:00
const _HermesInternal = HermesInternal;
obj5.error = "ViewModel instance '" + name + "' not found";
return obj5;
}
2026-07-23 10:11:24 +00:00
} else if (closure_4) {
instanceByName1 = closure_0.createInstance();
2026-07-20 16:05:17 +00:00
} else {
2026-07-23 10:11:24 +00:00
instanceByName1 = closure_0.createDefaultInstance();
2026-07-20 16:05:17 +00:00
}
const obj6 = {};
let tmp7 = null;
if (null != instanceByName1) {
tmp7 = instanceByName1;
}
obj6.instance = tmp7;
obj6.needsDispose = true;
return obj6;
}
}
} else {
obj = { instance: undefined, needsDispose: false };
return obj;
}
2026-07-23 10:11:24 +00:00
})(closure_0, name, artboardName, viewModelName, closure_4);
2026-07-20 16:05:17 +00:00
let current = tmp.instance;
if (current) {
current = tmp10.current;
}
if (current) {
tmp10.current(tmp.instance);
}
return tmp;
}, (needsDispose) => {
if (tmp) {
2026-07-23 10:11:24 +00:00
callback(name[3]).callDispose(needsDispose.instance);
const obj = callback(name[3]);
2026-07-20 16:05:17 +00:00
}
}, items);
const items1 = [disposableMemo.error];
if (tmp8) {
if (null === disposableMemo.instance) {
let _Error = Error;
let str = "useViewModelInstance: Failed to get ViewModelInstance. Ensure the source has a valid ViewModel and instance available.";
if (disposableMemo.error) {
2026-07-23 10:11:24 +00:00
let _HermesInternal = HermesInternal;
2026-07-20 16:05:17 +00:00
str = "useViewModelInstance: " + disposableMemo.error;
}
2026-07-23 10:11:24 +00:00
let prototype = _Error.prototype;
2026-07-20 16:05:17 +00:00
_Error = new _Error(str);
throw _Error;
}
}
const instance = disposableMemo.instance;
if (disposableMemo.instance) {
obj = { instance, error: null };
let obj1 = obj;
} else if (undefined === instance) {
obj = { instance: undefined, error: null };
obj1 = obj;
} else {
obj1 = { instance: null, error: tmp12 };
}
return obj1;
};