Skip to content

Instantly share code, notes, and snippets.

@chiquitinxx
Last active December 14, 2015 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chiquitinxx/1851d1bdb5a71980bab6 to your computer and use it in GitHub Desktop.
Save chiquitinxx/1851d1bdb5a71980bab6 to your computer and use it in GitHub Desktop.
Groovy components coming in grails 3 plugin
//Define your component in a groovy class
package foo.bar
class Counter {
static renderAfter = ['inc', 'dec']
static style = 'button { background-color: red; }'
int value = 0
void inc() {
value++
}
void dec() {
value--
}
void render() { //Markup template engine
h1 value.toString()
p {
button(onclick: 'dec', '-')
button(onclick: 'inc', '+')
}
}
}
//Add to your gsp's with:
<grooscript:component src='foo.bar.Counter'/>
//And then use in your gsp
<counter></counter>
<counter value="5"></counter>
//Not using implementations as React or Polymer. Just using custom components and shadow dom (http://webcomponents.org/)
//The idea, is the component renders when you change something visual or important
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment