stampit-org / stamp-specification

The Stamp Specification: Composables
434 stars 16 forks source link

Allow metadata (descriptors) merging override #102

Closed koresar closed 7 years ago

koresar commented 8 years ago

My mental model of stamps is following:

Thus, the metadata collection is the corner stone of the stamps philosophy. We should not limit people on how they merge metadata.

I'm thinking of allowing people to overwrite the mergeComposable similar to the initializers way. In other words - if user specified a merging callback function and it returned non-undefined then use the returned value as a new descriptor. (Will provide code examples later.)

ericelliott commented 8 years ago

Be careful not to over-complicate things...

Make sure you answer "is this really needed?" =)

koresar commented 8 years ago

I'm yet to need this in JS. Although, it might be useful for other languages.

This idea needs a deep thought though.

unstoppablecarl commented 8 years ago

I cannot think of a use case that could not be solved by init

koresar commented 8 years ago

yes. Either init or infected compose.

I'm just thinking of other languages. It could be useful there. Could not. :)

koresar commented 8 years ago

Code example as promised:

const WrappedMergeStamp = compose({
  mergeDescriptor(dstDescriptor, srcDescriptor) {
    // my own algorithm to merge metadata.
    console.log(src);
    // Can wrap original compose.
    return Object.assign({}, compose(dst, src).compose);
  }
});

WrappedMergeStamp.compose({ properties: { a: 1 } }).compose({ methods: { b() {} } });

Will print:

{ properties: { a: 1 } }
{ methods: { b: [Function: b] } }

Again. I don't see JS need that given that we have infected compose. But other languages are not as flexible (e.g. Java or C#).

koresar commented 7 years ago

This idea was continued with the #109 proposal. Closing.