CSNW / d3.compose

Compose complex, data-driven visualizations from reusable charts and components with d3
http://CSNW.github.io/d3.compose/
MIT License
697 stars 24 forks source link

Simplify and refactor property #31

Closed timhall closed 9 years ago

timhall commented 9 years ago

Previously, name was required as key to store property on internal __properties object and ended up being added boilerplate for every property that repeated the prototype key. Since this functionality is internal, the name isn't exposed and a unique id can be used instead which can then be used to determine the name, if necessary. To account for functions as default_value, type: 'Function' has been added, but it could affect directly set values. Instead, type has been removed, default_value is always evaluated if it's a function, and functions as default_value should be wrapped in a function. Finally prop_key is no longer available (__properties is always used).

Before:

a: property('a', {
  default_value: function defaultFn() {},
  type: 'Function'
}),
b: property('b')

After:

a: property({
  default_value: function() { return defaultFn() {} }
}),
b: property()

Changes: