Closed tarelli closed 10 years ago
Just to add more detail to this - we need to have a state-tree client side made up of nested entities, each entity having one or more aspects. We need to be able not only to store key-value pairs representing variables names and their values but also to call methods on these entities that will be mapped to the server-side API.
We have a sort of object orientation already for client side objects such as simulation in js - but these are currently a global object we need to be able to instantiate these classes so that we can build up a tree made of instances.
We need to find a suitable framework to do this. If anybody has ideas please share them!
@gidili I'm not entirely sure if I understand the difference between an entity and an aspect so sorry if I'm missing something, but this seems like it might be a job for backbone associations
This would allow you to define a backbone structure for nested models that looks something like the following:
var AspectModel = Backbone.Model.extend({
defaults:{
name: null,
field1: null,
field2: null
}
})
var AspectCollection = Backbone.Collection.extend({
model: AspectModel
})
var EntityModel = Backbone.Model.extend({
defaults:{
name: null,
aspects: null,
children: null
},
relations: [
{
type: Backbone.Many,
key: 'aspects',
relatedModel: AspectModel,
collectionType: AspectCollection
},
{
type: Backbone.Many,
key: 'children',
relatedModel: core.Backbone.Self
}
]
})
This could be deserialized to Java classes that look something like:
public class Entity {
public String name;
public List<Aspect> aspects;
public List<Entity> children
public Entity(){}
}
public class Aspect {
public String name;
public String field1;
public String field2;
public Aspect() {}
}
I'm simplifying a lot here for the sake of clarity
@mlolson for entity/aspect description have a look at http://docs.geppetto.org/en/latest/simtutorial.html
@mlolson that sounds like a slick way of doing it. I remember @jrmartin also looked into backbone before but we didn't end up using it as we just wanted an elegant way to handle callbacks at the time.
@gidili we are using backbone for the widgets already https://github.com/openworm/org.geppetto.frontend/blob/master/src/main/webapp/js/widgets/Widget.js
@tarelli oh cool - I hadn't even noticed :)
@gidili I'm a fan of backbone because it allows you to do some cool event driven stuff. For example, you can attach listeners to trigger callback functions on "change" or "set" events.
@mlolson sounds close to what we need here --> #112 also would be handy to propagate refresh actions to appropriate listeners every time the state tree changes on the client.