X-12 / andromeda

0 stars 0 forks source link

Create template for how system values are watched #30

Closed jextrevor closed 7 years ago

jextrevor commented 7 years ago

As of yet, we haven't established a template or a reference for how systems watch other systems' values.

To avoid rewriting a lot of code, I propose that we make a universal "setter" function that handles setting the value itself, updating Socketio clients, and updating systems who are watching that value. We would then have every system class inherit that setter function.

Here's a bit of pseudocode: class System { this.name = "System" this.callbacks = {value1:[ ],value2:[ ]} set(ident,value) { this[ident] = value io.emit(this.name+"."+ident, value) for(c in this.callbacks[ident]){ call c }} addcallback(ident,callback){ this.callbacks[ident].add(callback) etc


class Power extends System ... turnOn(){ this.set("on",true) etc

So, to set a value and notify all observers (other systems and clients), use set(), and to add a callback (function to be executed when a systems value changes), use addcallback(). What are your thoughts?

jextrevor commented 7 years ago

The Power system would have a line in the constructor that would be like: this.name = "Power" so the universal setter function would know how to name events.

DakotaHarward commented 7 years ago

Looks good, I say to move forward.