Skip to content

Init-property vs. injecting stamps as properties #46

Description

@MaximusHaximus

I've made a few stamps where I inject other stamps as properties using .props({...}) for dependency injection purposes (testing/mocking).

I'd like to use init-properties stamp to automatically initialize some props that are stamps and have their arguments automatically namespaced (👍 ), but in some cases in my code, I am injecting stamps as .props() where those stamps are not intended to be initialized during initialization of the parent stamp. e.g.

const MyStamp = require('./MyStamp');

const asyncStampFactory = stampit
.init(function(fetchRemoteStampConfiguration, numStamps) {
 this.fetchRemoteStampConfiguration = fetchRemoteStampConfiguration;
 this.numStamps = numStamps;
})
.props({ myStamp })
.methods({
  makeSomestamps() {
    const stamps = [];

    for(var x = 0; x < numStamps x += 1) {
      const stampConfig = await this.fetchRemoteStampConfiguration(x)
      stamps[x] = this.myStamp(stampConfig);
    }
    return  stamps;
  }
});

return asyncStampFactory;

Note that I won't be making a single stamp from the myStamp prop, but an array of them -- and I can't create the array of stamps on stamp initialization as the point of this stamp is to do some async fetching and return instances of the myStamp per result that was fetched.

init-properties seems to conflict with this.

I'm wondering if there might be a justification here for being able to configure the init-property stamp not to automatically initialize ALL stamp properties, but only some?

My instinct was to move myStamp to .configuration() and then use this.config.myStamp() in the loop to create instances instead, and only put stamps in .props() that should be auto initialized with values that are available during stamp initialization.

Would appreciate any insights :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions