antonmedv / monkberry

Monkberry is a JavaScript library for building web user interfaces
https://monkberry.js.org
MIT License
1.49k stars 78 forks source link

Simples examples folder #22

Closed minimok closed 8 years ago

minimok commented 8 years ago

Monkberry is very nice indeed! Would be really cool to see some "simple" examples of how to use events - e.g. I have an object 'Fruit' that has a name property and 1 method 'handleClick' which, say, logs to console every time it's invoked.

I pass a Fruit instance new Fruit() to view.update(..)

<h1>{{name}}</h1>

<button onClick="{{handleClick}}">ClickMe</button>

The name of my fruit shows up perfectly. But, I'm not getting anything happening when I try and call its handleClick method...a simple example would probably illustrate how to do this in 5 secs.

Cheers for any pointers...

catindev commented 8 years ago

@minimok try event handling examples from docs.

minimok commented 8 years ago

Thanks. I forgot to mention I've read the docs. None of them illustrate passing an object into the DOM and then using DOM events to execute methods belonging to the specific object that was passed in (aka OOP). I've written a brutal hack to solve the issue - basically removing all event-handling from monkberry's role in the app and using it purely to render data...which it's very good at.

antonmedv commented 8 years ago

There a few solution: dom delegating/event directives/direct event listeners. Read more at docs: http://monkberry.js.org/docs/event-handling