jdhenke / celestrium

A javascript library to visualize graphs.
MIT License
2 stars 1 forks source link

plugin architecture refactor to instance attributes #93

Closed jdhenke closed 10 years ago

jdhenke commented 10 years ago

// @willzeng, i'd be interested in your thoughts on this

i've thought of a different way to share instances of each plugin with each other. it essentially requires classes to articulate the instance dependencies it has and assigns each instance of a plugin attributes which are the instances of the other plugins.

Example Interface

class Plugin

  # string unique to all other plugins
  @uri: "Plugin"

  # dictionary mapping attribute name to URI of other plugin
  @needs:
    "plugin2": "Plugin2"

  # now attributes are available, even in the constructor
  constructor: () ->
    expect(@plugin2).toBeDefined()

So each plugin class specifies

jdhenke commented 10 years ago

If you're curious about implementation, here's how, given a class definition, it can be extended with certain attributes to make them available in the constructor without modifying the original definition.

class Person
  @uri: "Person"
  constructor: () ->
    console.log @name

class Dude extends Person

Dude::name = "joe"

new Person()
new Dude()

This prints

undefined
joe
willzeng commented 10 years ago

This would certainly be good as Plugins become numerous and interdependent (we should be able to produce a nice GraphView of the plugin dependencies...)

Do you know how to implement expect(@plugin2).toBeDefined() ?

jdhenke commented 10 years ago

That's just a jasmine syntax for saying, @plugin2 will be defined in the constructor.

jdhenke commented 10 years ago

// @willzeng

(we should be able to produce a nice GraphView of the plugin dependencies...)

image

I generated this programmatically leveraging my new infrastructure. So meta...