MCPcopy Index your code
hub / github.com/ionic-team/capacitor / wrapper

Function wrapper

core/src/runtime.ts:102–123  ·  view source on GitHub ↗
(...args: any[])

Source from the content-addressed store, hash-verified

100 const createPluginMethodWrapper = (prop: PropertyKey) => {
101 let remove: (() => void) | undefined;
102 const wrapper = (...args: any[]) => {
103 const p = loadPluginImplementation().then((impl) => {
104 const fn = createPluginMethod(impl, prop);
105
106 if (fn) {
107 const p = fn(...args);
108 remove = p?.remove;
109 return p;
110 } else {
111 throw new CapacitorException(
112 `"${pluginName}.${prop as any}()" is not implemented on ${platform}`,
113 ExceptionCode.Unimplemented,
114 );
115 }
116 });
117
118 if (prop === 'addListener') {
119 (p as any).remove = async () => remove();
120 }
121
122 return p;
123 };
124
125 // Some flair ✨
126 wrapper.toString = () => `${prop.toString()}() { [capacitor code] }`;

Callers

nothing calls this directly

Calls 4

loadPluginImplementationFunction · 0.85
createPluginMethodFunction · 0.85
removeFunction · 0.85
thenMethod · 0.80

Tested by

no test coverage detected