Skip to content

Commit

Permalink
Restore pys-on* events with original behavior, deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffersGlass authored and marimeireles committed Sep 12, 2022
1 parent 990d51e commit f9a562c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pyscriptjs/src/components/pyscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,17 @@ async function createElementsWithEventListeners(runtime: Runtime, pyAttribute: s
}
const handlerCode = el.getAttribute(pyAttribute);
const event = pyAttributeToEvent.get(pyAttribute);
el.addEventListener(event, async () => {await runtime.run(handlerCode)});

if (pyAttribute === 'pys-onClick' || pyAttribute === 'pys-onKeyDown'){
console.warn("Use of pys-onClick and pys-onKeyDown attributes is deprecated in favor of py-onClick() and py-onKeyDown(). pys-on* attributes will be deprecated in a future version of PyScript.")
const source = `
from pyodide.ffi import create_proxy
Element("${el.id}").element.addEventListener("${event}", create_proxy(${handlerCode}))
`;
await runtime.run(source);
}
else{
el.addEventListener(event, async () => {await runtime.run(handlerCode)});

// TODO: Should we actually map handlers in JS instead of Python?
// el.onclick = (evt: any) => {
Expand Down

0 comments on commit f9a562c

Please sign in to comment.