stampit-org / stamp

Stamps - better OOP model
https://stampit.js.org
MIT License
25 stars 3 forks source link

Add configure stamp #22

Closed danielkcz closed 7 years ago

danielkcz commented 7 years ago

It's very trivial and doesn't make much sense for regular stamps. However, with Privatize it's perfectly sane to do this since it will disappear from replaced instanced.

import Configure from '@stamp/privatize/configure';
import Privatize from '@stamp/privatize';

compose(Configure, Privatize, {
    configuration: {
        secret: 'mykey'
    },
    methods: {
        encrypt(value) {
          const { secret } = this.stampConfiguration;
          // run encryption with secret while it's still hidden from outside
        }
    }
})

Thinking if it would actually good idea to incorporate it as optional part of Privatize stamp to avoid double import. Something like compose(Privatize.withConfigure()). Or simple static property to allow import Privatize, { Configure } from '@stamp/privatize'. What do you think @koresar ?

koresar commented 7 years ago

Good PR! I'd merge if the stamp was a separate @stamp/auto-configure package.

About preventing double import:

danielkcz commented 7 years ago

Ok nevermind, it was just an idea, I am not feeling for doing it as a separate package. Considering it is a two liner and with the separate package, I would need another two lines (and installation) to actually use it, it's not really worth it.

danielkcz commented 7 years ago

Btw, you have there privatizeMethod, so having privatizeConfig(prefix = 'stamp') the same way could be easily seen as a part of the package and not really like something extra because I said before it doesn't really make sense to expose config like this without privatizing it.

koresar commented 7 years ago

Sounds like an idea. I'll think about it.

On Sun, 23 Apr 2017, 16:20 Daniel K. notifications@github.com wrote:

Btw, you have there privatizeMethod, so having privatizeConfig(prefix = 'stamp') the same way could be easily seen as a part of the package and not really like something extra.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stampit-org/stamp/pull/22#issuecomment-296422571, or mute the thread https://github.com/notifications/unsubscribe-auth/ABjCL4npe21RKE2Q5HNLGZsMZ0C2b36Pks5ryu2egaJpZM4NFJE2 .