yeoman / generator

Rails-inspired generator system that provides scaffolding for your apps
http://yeoman.io
BSD 2-Clause "Simplified" License
1.2k stars 298 forks source link

Config debounce prevents hooked subgenerators from using config? #376

Closed ajthor closed 10 years ago

ajthor commented 10 years ago

this.save = .debounce(.bind(this.forceSave, this), 5);

The five second debounce prevents subgenerators from using the config store if hooked. Works fine if called individually. I've resorted to redefining the save function without debounce in my sub generator constructor. Any way around this or thoughts?

SBoudrias commented 10 years ago

Well, not debouncing is an option, but this mean it'll write to disk each time it's called - this could be quite a performance hit. (Up to now the Storage have been though to save state between session, not to be a communication way - but your concern is legitimate)

Is your generator on Github? I'd like to see your use case more clearly. Maybe you could pass information between generator in another way...

ajthor commented 10 years ago

This is what I've come up with: https://github.com/ajthor/generator-mean

Trying to save an object of modules and build at the end along with index.html and other files which need the information before build.

SBoudrias commented 10 years ago

OK so,

You can first listen for a save event on the storage before calling the hook.

Or, you can .forceSave() the storage to make sure the saving is done before calling the hook.

Relevant section in code: https://github.com/yeoman/generator/blob/master/lib/util/storage.js#L47-L50

ajthor commented 10 years ago

Brilliant.

Any other ideas for passing configuration values from generator to hooked subgenerators?

SBoudrias commented 10 years ago

Well, using .hookFor('name', { foo: 1 }) you can pass arguments to the generator.

So you could handle them too, but using the Storage with forceSave seems ok to me. It keeps things decoupled if you're saving shared configuration options.

ajthor commented 10 years ago

That was the idea, yeah. Okay. I thought as much. Thanks. I really appreciate the help, @SBoudrias.