stampit-org / stampit

OOP is better with stamps: Composable object factories.
https://stampit.js.org
MIT License
3.02k stars 102 forks source link

"composers" experiments implementation #276

Closed koresar closed 7 years ago

koresar commented 7 years ago
koresar commented 7 years ago

After trying it out I found that the simplest and the most universal API would be this:

const HaveComposer = stampit.composers(function ({stamp, composables}) {
  console.log('Resulting stamp:', stamp);
  console.log('Was made of composables:', composables);
});

The implementation will still be specification compatible. The "composers" will be attached to the deepConfiguration as the .composers array. It will be deduped just like initializers array is.

The provided composers will be invoked immediately after being passed to the compose():

stampit.compose(AnyStamp, {composers({stamp, composables}) {
  assert(composables[0] === AnyStamp);
  assert(typeof composables[1] === 'object');
}});
danielkcz commented 7 years ago

Can you perhaps provide some real use case scenario? I still have a hard time to realize what this is good for actually. Even after rereading proposal couple times :) Consider me as the outside user on this and if there will be big barrier to understand this, not many people is actually going to use it.

Edit: My understanding is surely limited by fact that I had no need for infection just yet.

koresar commented 7 years ago

Providing the use case scenarios as a Fun with Stamps. Episode 11. Interfering composition https://medium.com/@koresar/fun-with-stamps-episode-11-interfering-composition-7abc44ac1f99 /cc @FredyC @amelon

koresar commented 7 years ago

Done