I'm trying to figure out if in jco-transpile bindings (e.g. preview2-shims or some other custom wit implementation) there's any kind of state.
In wasmtime bindings, you implement everything as a trait, and the first parameter is always &mut self. You can keep any state inside self. Is there anything like this in Jco?
I'd like to use this in cases where there are multiple wasm components running on the same page, and I wanna customize the behavior according to which component called a function.
This topic was moved here from #general > Detecting Which Component Called a Host Function Jco by Alex Crichton.
I can't recall; @Till Schneidereit should know, or perhaps @Tomasz Andrzejak
Hey @Mendy Berger could you expand on what you mean here? Do you mean whether preview2-shim depend on any global state outside the module? They are ES modules, so is the question more whether there is any use of globalThis?
Either way, I think a quick way to figure out would be to inspect code from a transpiled component -- it's not too difficult to scan (ignoring any complaints about how the code is written/what code is there, of course!)
With regards to shims, that's entirely up to shims and how you bundle -- in general the shims are also modules, but you could easily write a shim that does depend on global state or one that does not. It also depends on what you're targeting with the shim -- obviously the Node shim versus browser shim (which is pretty incomplete!) must depend on platform primitives, which are globals in a sense... There's no place to pass in a custom implementation of platform primitives like TextEncoder for example, but not sure if that's what you mean by state.
A good place to look might be filesystem implementation from P2-shim -- for example the preopenEntries array is clearly state, but not sure that's what you're referring to.
When you say customize their behavior according to which component called a function, do you mean... when each component calls an import? If that's the case, you should be able to achieve that by wrapping the imports object (or any individual import) with a proxy.
Last updated: Jan 09 2026 at 13:15 UTC