Something went wrong. Try again.
javascript for 🐜's, a tiny runtime with big ambitions antjs.org
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768const knownServerReferences = new WeakMap();const FunctionBind = Function.prototype.bind;const ArraySlice = Array.prototype.slice;
function defaultEncodeFormAction() { return { name: '$ACTION_ID_demo', method: 'POST' };}
function registerBoundServerReference(reference, id) { if (knownServerReferences.has(reference)) return;
knownServerReferences.set(reference, { id, originalBind: reference.bind, bound: null, });
Object.defineProperties(reference, { $$FORM_ACTION: { value: defaultEncodeFormAction, }, bind: { value: bind, }, });}
function bind() { const referenceClosure = knownServerReferences.get(this); if (!referenceClosure) return FunctionBind.apply(this, arguments);
const newFn = referenceClosure.originalBind.apply(this, arguments); const args = ArraySlice.call(arguments, 1);
knownServerReferences.set(newFn, { id: referenceClosure.id, originalBind: newFn.bind, bound: Promise.resolve(args), });
Object.defineProperties(newFn, { $$FORM_ACTION: { value: this.$$FORM_ACTION, }, bind: { value: bind, }, });
return newFn;}
async function action(x) { return x;}
registerBoundServerReference(action, 'demo');
console.log(`action.bind.eq.custom:${action.bind === bind}`);console.log(`action.formAction.type:${typeof action.$$FORM_ACTION}`);
const bound = action.bind(null, 1);
console.log(`bound.type:${typeof bound}`);console.log(`bound.bind.eq.custom:${bound.bind === bind}`);console.log(`bound.formAction.type:${typeof bound.$$FORM_ACTION}`);console.log(`bound.formAction.name:${bound.$$FORM_ACTION ? bound.$$FORM_ACTION().name : 'missing'}`);