colinmeinke / wilderness

An SVG animation API
https://wilderness.now.sh
MIT License
154 stars 8 forks source link

Remove shape inheritance #24

Closed colinmeinke closed 7 years ago

colinmeinke commented 7 years ago

Currently when creating a shape, additional plain shape objects will inherit properties from the initial plain shape object:

const from = {
  type: 'circle',
  r: 10,
  cx: 50,
  cy: 50,
  fill: '#E54',
  moveIndex: 2,
  reverse: true,
};

const to = {
  r: 20,
};

shape( from, to );

The to shape in the above example will inherit every from property apart from r. Currently to avoid this behaviour the to plain shape object should redefine the undesired properties with the default value. e.g. reverse: false.

Currently I'm planning to abandon inheritance altogether and suggest plain Javascript if inheritance is required.

const sharedProperties = {
  type: 'circle',
  cx: 50,
  cy: 50,
  fill: '#E54',
};

const from = {
  ...sharedProperties,
  r: 10,
  moveIndex: 2,
  reverse: true,
};

const to = {
  ...sharedProperties,
  r: 20,
};

shape( from, to );
colinmeinke commented 7 years ago

After further thought I'm certain that removing inheritance is the best way forward.