#1550 Allow access to 'once' method hidden variable

qualidafial Fri 3 Jun 2011

One thing that has bothered me about once methods is that you can't optimize depending on whether the method has been run yet.

One example would be if we changed each EventListeners in FWT classesbe once methods instead of fields with private set. If the method hasn't been called yet (e.g. to add a listener) then there's no point instantiating the object to fire an event that goes nowhere.

I'm proposing we allow access to the underlying cache variable using the field syntax:

@Transient once EventListeners onAction() { EventListeners() }

Void click() {
  &onAction?.fire(Event { id = EventId.action; })
}

This syntax would only be supported for getting the implicit field, but not setting it.

brian Sun 5 Jun 2011

Cool idea, definitely something to think about. Although at the immediate moment, I am not sure I want to enhance once functionality until more thought is given to if/how once should work with const classes.

qualidafial Wed 8 Jun 2011

For purposes of serialization, once methods are excluded, correct? I'm working on a patch to replace the EventListeners fields in FWT with once methods, and need to know if I can get rid of @Transient facets.

brian Wed 8 Jun 2011

Yes once methods are treated as methods, not fields

Login or Signup to reply.