stampit-org / stamp-specification

The Stamp Specification: Composables
434 stars 16 forks source link

Proposal: new metadata "name" to set stamp's `.name` #121

Closed koresar closed 6 years ago

koresar commented 6 years ago

I'm using the stamps extensively. Most of my stamps are named using this utility stamp - https://www.npmjs.com/package/@stamp/named I would like to stop importing that module and just make the Stamp.name a built-in feature.

Another reason to add "name" support are classes. Classic OOP classes have names. Stamps are all anonymous.

One more reason why name built in support is so important - I want to make a proposal to (any) program language to support stamps natively instead of freaking classes. Like so:

stamp MyStamp extends AnotherStamp {
}

In the example above the MyStamp would become the stamp's name. (In Javascript it's MyStamp.name.)

Proposed changes to the specification:

Add one more descriptor metadata - name. Its type will be "string". It will be stored on Stamp.compose.staticPropertyDescriptors.name.value.


const Stamp = compose({
name: "MyName"
});
console.log( Stamp.name ); // "MyName"
console.log( Stamp.compose.staticPropertyDescriptors.name.value ); // "MyName"

const DerivedStamp = Stamp.compose(); console.log( DerivedStamp.name ); // still "MyName" console.log( DerivedStamp.compose.staticPropertyDescriptors.name.value ); // still "MyName"



The is one quirk:
> It is impossible to set property `.name` in ES5, but only in ES6.
koresar commented 6 years ago

In couple of weeks, if no objections, I'd add the change to spec.

koresar commented 6 years ago

I gave it a second thought. The feature would better fit the stampit module rather than the specification. Here is the function to put it in: https://github.com/stampit-org/stamp/blob/00020b55b1e679da3aafcc67aaf60f6d1b3897fc/packages/it/index.js#L15