* @param {string | number | boolean} [key]
(key)
| 23 | * @param {string | number | boolean} [key] |
| 24 | */ |
| 25 | function create_instance(key) { |
| 26 | /** @type {RemoteForm<T>} */ |
| 27 | const instance = {}; |
| 28 | |
| 29 | instance.method = 'POST'; |
| 30 | instance.onsubmit = () => {}; |
| 31 | |
| 32 | Object.defineProperty(instance, 'enhance', { |
| 33 | value: () => { |
| 34 | return { action: instance.action, method: instance.method, onsubmit: instance.onsubmit }; |
| 35 | } |
| 36 | }); |
| 37 | |
| 38 | const button_props = { |
| 39 | type: 'submit', |
| 40 | onclick: () => {} |
| 41 | }; |
| 42 | |
| 43 | Object.defineProperty(button_props, 'enhance', { |
| 44 | value: () => { |
| 45 | return { type: 'submit', formaction: instance.buttonProps.formaction, onclick: () => {} }; |
| 46 | } |
| 47 | }); |
| 48 | |
| 49 | Object.defineProperty(instance, 'buttonProps', { |
| 50 | value: button_props |
| 51 | }); |
| 52 | |
| 53 | /** @type {RemoteInfo} */ |
| 54 | const __ = { |
| 55 | type: 'form', |
| 56 | name: '', |
| 57 | id: '', |
| 58 | /** @param {FormData} form_data */ |
| 59 | fn: async (form_data) => { |
| 60 | const event = getRequestEvent(); |
| 61 | const state = get_event_state(event); |
| 62 | |
| 63 | state.refreshes ??= {}; |
| 64 | |
| 65 | const result = await run_remote_function(event, true, form_data, (d) => d, fn); |
| 66 | |
| 67 | // We don't need to care about args or deduplicating calls, because uneval results are only relevant in full page reloads |
| 68 | // where only one form submission is active at the same time |
| 69 | if (!event.isRemoteRequest) { |
| 70 | (state.remote_data ??= {})[__.id] = result; |
| 71 | } |
| 72 | |
| 73 | return result; |
| 74 | } |
| 75 | }; |
| 76 | |
| 77 | Object.defineProperty(instance, '__', { value: __ }); |
| 78 | |
| 79 | Object.defineProperty(instance, 'action', { |
| 80 | get: () => `?/remote=${__.id}`, |
| 81 | enumerable: true |
| 82 | }); |
no test coverage detected