dolittle / Bifrost

This is the stable release of Dolittle till its out of alpha->beta stages
Other
110 stars 32 forks source link

Use actual read model type, if found, for creating instances data retrieved with readModelOf... and queryFor #237

Closed einari closed 11 years ago

einari commented 11 years ago

Also modify the readModel proxy to not hold observables - they are read only.. (Kinda says so in the name)

einari commented 11 years ago

Proxy generation of readModel is wrong - properties should not be observable - defies the whole purpose of being "READ ONLY". Properties should just be initialized with default values based on the type of the property in C# during proxy generation. If property is int, default value becomes 0, string = "", Guid = Guid.Empty() and so forth...

Query.js : when retrieving data, map the data to the correct read model type by creating an instance of it and populating it. This goes for ReadModelOf as well, so I suggest putting in a third system that both can take a dependency to that system that takes an object literal and creates an instance of the read model and copies the values from the object literal to the read model instance (formerly known as mapping :) ). This means that the ReadModelOf and Query in JavaScript needs to be aware of what the ReadModel is - so, on the Proxy Generation, put in the reference to ReadModel type (readmodels.[TheType]) the type can then be forwarded to the third system and it can use .create() to create an instance from that!

E.g.

Bifrost.namespace("queries", {
    allEmployees: Bifrost.read.Query.extend(function() {
         var self = this;
         this.name = "allEmployees";
         this.readModel = readModels.employee;
    })
});

The base type (query / readModelOf) should have readModel sitting on it as default, pointing to Bifrost.Type as type.

pavsaund commented 11 years ago

Hooked up Query.js and ReadModelOf. Need to update the proxy generation though. Look at https://github.com/dolittle/Bifrost/tree/Issue237