Skip to content

RFC: Wetland fundamentals

Wesley Overdijk edited this page Aug 4, 2016 · 2 revisions
  • Repository.
  • Entity.
  • Entity has schema method and repository method (static).
  • EntityManager populates entities (not repository).
  • Repository has "crud blueprints". Custom queries can be built using query builder.
  • Pubsub (also internal!)
  • Research for QL (I need to know the aliases in order for me to populate entities).

Stuff

Entity

Still not sure if I want to use Typescript. Without it, the schema definition would be something like:

class Foo {
  constructor() {
    this.products = new ArrayCollection();
    this.name     = null;
  }

  static schema() {
    return [
      Mapping.field(Foo, 'name', {type: 'varchar', length: 255}),
      Mapping.manyToMany({
        entity    : 'Product',
        inversedBy: 'categories',
        dominant  : true,
        cascade   : 'delete'
      })
    ];
  }
}

Proxy

  • Store original value, mark as non-dirty when set back

EntityManager

  • Use _dirty to allow a reset() method (reset entity to initial state).

ArrayCollection

  • Prevent duplicates.
  • Set Proxy for ArrayCollection to detect changes in relations (only care about PK)
class ArrayCollection extends Array {
  add(...items) {
    items.forEach(item => {
      if (!this.includes(item)) {
        this.push(item);
      }
    });

    return this;
  }

  remove(...items) {
    items.forEach(item => {
      let itemIndex = this.indexOf(item);

      if (itemIndex > -1) {
        this.splice(itemIndex, 1);
      }
    });

    return this;
  }
}
Clone this wiki locally