swiss icon indicating copy to clipboard operation
swiss copied to clipboard

Sinuous+swiss

Open kethan opened this issue 4 years ago • 6 comments

In the below example I see it updates and it renders twice.

https://codepen.io/kethan-the-selector/pen/mdVLjRQ?editors=1010

can anyone point my mistake?

kethan avatar Jul 09 '20 11:07 kethan

Nice example, thanks for putting this together! Sinuous doesn't need the use of the update method. It should only create the template once, in the constructor or in the connected callback, seems not documented I'm noticing.

https://github.com/luwes/swiss/blob/master/packages/swiss/src/swiss.js#L34

This works https://codepen.io/luwes/pen/vYLjazb?editors=1010

luwes avatar Jul 09 '20 12:07 luwes

@luwes thanks it was simple!. Yes without documentation I am breaking my head how to use it. any more detail doc will be helpful. Thanks.

kethan avatar Jul 09 '20 12:07 kethan

And how do i define event handler outside of swiss. may be in HTML tag like <sin-counter count="10" onclick=fun()></sin-counter>

kethan avatar Jul 09 '20 12:07 kethan

that should work like expected, the custom element extends the HTMLElement so it gets it from that base class.

to fire custom events, check some code here https://github.com/luwes/playerx/blob/5d2004614472de73840382c12348316c07434538/packages/playerx/src/playerx.js#L356-L356

luwes avatar Jul 09 '20 15:07 luwes

Oh thanks. One final doubt. How do I send function from attribute or setAttribute?

let obj = {
	count: 3,
	click: () => {
		console.log("clicked!");
	}
}

kethan avatar Jul 09 '20 18:07 kethan

@kethan via attributes is not possible. it can only be a string or stringified value. a function has to go through a property. Sinuous templates use props by default so something like

html`<a onclick=${myfunction} />` 

luwes avatar Jul 11 '20 13:07 luwes