Hi Andi,

(Thanks for writing while on your vacation!)

Andi Vajda wrote:

It seems that what you want could be done with yet another react-to-attribute-change trick.

We already have:

  - monitors called on a change in an attribute of a given name, globally
- watchers called on a change in a given collection attribute on a given
    item (synchronous and asynchronous)
  - watchers called when an item of a given kind is created, deleted or
    stamped
  - watchers called when a given item changes
- onValueChanged() called on an item when any of its chandler attributes
    change

I know we have lots of mechanisms already, and I'm proposing another because I don't think this use case is solved well by any of the existing mechanisms, without a bunch of supporting code cluttering up a lot of the domain model. I agree that onValueChanged is too big a hammer; during our conversation with Grant yesterday, Jeffrey and I talked a little about potentially being able to replace recurrence's use of onValueChanged with the new mechanism I'd proposed, and I'm sure we're misusing more of the existing mechanisms now, and others could potentially be replaced by this.

How about getting rid of onValueChanged() which is too big of a hammer and replace it with what I think you're suggesting - maybe I'm oversimplifying here - namely a new attribute aspect naming a method to invoke on an item when the attribute changes ?

The same method name could be used for multiple attributes, of course.
That's kind of the reverse of what I was suggesting: the method name hangs off any attribute that needs the method to be called, instead of hanging it off the attribute the method updates. I think it might work, though - something like:

class ContentItem(schema.Item):
   nextImportantDate = schema.One(schema.DateTime)
   lastModified = schema.One(schema.DateTime)
def updateNextImportantDate(self, attribute):
       self.nextImportantDate = whatever
def updateLastModified(self, attribute):
       self.lastModified = datetime.now()
class Note(ContentItem):
   nextReminderTime = schema.One(schema.DateTime,
                                 onChange='updateNextImportantDate')

class EventMixin(ContentItem):
   startTime = schema.One(schema.DateTime,
                          onChange=('updateNextImportantDate',
                                    'updateLastModified'))

This does feel strange to me in that the dependencies that updateNextImportantDate considers have to be recorded far from the definition of updateNextImportantDate and the nextImportantDate attribute itself.

Also, using this for lastModified (as I've shown) looks possible, though too wordy (since a parcel developer would have to remember to put "onChange=updateLastModified" on every user-editable attribute).

(I'm not sure how this would work in the stamping-as-annotation world, but I hand-waved that in my original proposal too.)

...Bryan


From the usage I've seen, onValueChanged() is not really needed anymore if we replace it with this new attribute aspect.

Andi..

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Open Source Applications Foundation "chandler-dev" mailing list
http://lists.osafoundation.org/mailman/listinfo/chandler-dev

Reply via email to