vadimtsushko / objectory

Unsupported: Objectory - object document mapper for server-side and client side Dart applications
MIT License
55 stars 12 forks source link

PersistentList causes "watcher propagation stopped" with Web UI #34

Closed kaisellgren closed 11 years ago

kaisellgren commented 11 years ago

The way we use PersistentList:

PersistentList<User> get managers => new PersistentList<User>(this, 'User', 'managers');

i.e. returning a new persistent list, causes:

Possible loop in watchers propagation, stopped dispatch.

Because I believe the list "changes" all the time when Web UI is trying to compare if it has changed:

<ul template iterate="manager in foo.managers">
  <li>{{ manager.name }}</li>
</ul>

Could we do something about this? Maybe implement == and hashCode?

vadimtsushko commented 11 years ago

I believe you may solve this problem slightly changing your model to somewhat like:

final PersistentList<User> _managers => new PersistentList<User>(this, 'User', 'managers');
PersistentList<User> get managers => _managers;
kaisellgren commented 11 years ago

You are right, I can take a different approach. However, I had to do something slightly different what you proposed, here's what works:

class Community extends BaseModel {
  Community() {
    _managers = new PersistentList<User>(this, 'User', 'managers');
  }

  PersistentList<User> _managers;
  PersistentList<User> get managers => _managers;
}

The one you mentioned, used arrow in assignment which does not work... either you specify a method (arrow), or you assign (= without arrow). And assignment doesn't work with this.

I'm wondering... since Web UI is a popular thing in the Dart world, should we mention something in the docs or maybe even suggest a different way to write this in the Objectory docs?

vadimtsushko commented 11 years ago

Silly mistake, i wrote code just here. Obviously I meant

final PersistentList<User> _managers = new PersistentList<User>(this, 'User', 'managers');
PersistentList<User> get managers => _managers;  

I believe there is better way to define List properties in model: I've just added getPersistentList method to PersistentObject (used similar to getEmbeddedObject) So class Person from test model now looks like:

class Person extends PersistentObject {
  String get firstName => getProperty('firstName');
  set firstName(String value) => setProperty('firstName',value);
  ....
  ....  
  Address get address => getEmbeddedObject('Address', 'address');

  Person get father => getLinkedObject('father');
  set father (PersistentObject value) => setLinkedObject('father',value);

  List<Person> get children => getPersistentList('Person','children');
}

property children constantly return same object.

All this in last version on pub.dartlang.org

kaisellgren commented 11 years ago

Good to know -- is this updated to all docs? Please do so if not :)

vadimtsushko commented 11 years ago

All docs are very old. Do you wish to help?

kaisellgren commented 11 years ago

I guess I could at the weekend. I'll bookmark this page as a reminder to myself. Can you add me as a collaborator to this repository? I won't push any radical code changes, if I ever do it's a separate branch.

vadimtsushko commented 11 years ago

Fork the repository and make a pull request whith your changes. I believe that's usual way to contribute on github