grails-events-push icon indicating copy to clipboard operation
grails-events-push copied to clipboard

A gorm event can only be used by one domain object

Open halfbaked opened this issue 12 years ago • 8 comments

Lets say I have this in my Events DSL:

'afterInsert' namespace: 'gorm', filter: com.mycompany.Dog, browser: true

Can I then add ?:

'afterInsert' namespace: 'gorm', filter: com.mycompany.Cat, browser: true

Would the following then be rendering Cats and Dogs

grailsEvents.on('afterUpdate', function(data) {  renderToTemplate(data)  });

I wonder if the gorm events are really compatible with a non-trivial client-side application. Perhaps the best strategy here is to just trigger custom events like newCat and newDog where appropriate.

halfbaked avatar Jul 31 '12 08:07 halfbaked

Unfortunately, the filters are exclusive and the last loaded topic will take precedence. I don't know yet how to properly let options to user there :)

smaldini avatar Jul 31 '12 08:07 smaldini

Totally understand. It is easy enough to define some custom events anyway. Hope I'm not too much of a headache with all these questions!

halfbaked avatar Jul 31 '12 08:07 halfbaked

Not at all, it's super cool to test ideas before release. With some feedbacks like yours, I've changed a ton of things (including platform-core events and Spring Integration plugin bits) !

Thank you again for every issues you submit !

smaldini avatar Jul 31 '12 08:07 smaldini

That's great to hear :)

I'm wondering what the Events DSL file is used for outside of events-push. I assume it has something to do with the registry, but I don't know, so bare that in mind with this proposal for the DSL (for events-push at least) that would look something like:

'newDog' topic: 'afterInsert', namespace: 'gorm', filter: com.mycompany.Dog
'newCat' topic: 'afterInsert', namespace: 'gorm', filter: com.mycompany.Cat

with the client operating as you might expect:

grailsEvents.on('newDog', function(data) {  renderToDogTemplate(data)  });
grailsEvents.on('newCat', function(data) {  renderToCatTemplate(data)  });

Now what about bringing all the issues I've raised here on git together into one solution:

'supportTicket/$ticketId/newComment' topic: 'afterInsert', namespace: 'gorm', filter: { message, request, params ->
     if (message instanceof TicketReply && message.ticketId = params.ticketId) return true
     else return false         
 }

Basically as you suggested previously the client/atmosphere topic name behaves like UrlMappings. I'm just coming at this from the perspective of a user of events-push, but I believe something of this form could be elegant and uber powerful.

halfbaked avatar Jul 31 '12 09:07 halfbaked

I initially planned something similar, it will probably come on M2.

smaldini avatar Jul 31 '12 14:07 smaldini

Yeah i found this thing also. Do we have this functionality in M3? I am already using M3 in my grails application but don't know how can i use the Gorm Event for more than 2 Domain Objects.

m16sikander avatar Nov 14 '12 18:11 m16sikander

what I currently do is, from the respective closures in the domain class I trigger a custom named event. For example

class Ticket {
  afterUpdate = {
    event('ticketUpdated', this)
  }
}

halfbaked avatar Nov 14 '12 18:11 halfbaked

Yeah cool beans.. Thanks much. This surely will work for me.

m16sikander avatar Nov 14 '12 20:11 m16sikander