Closed ajthor closed 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...
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.
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
Brilliant.
Any other ideas for passing configuration values from generator to hooked subgenerators?
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.
That was the idea, yeah. Okay. I thought as much. Thanks. I really appreciate the help, @SBoudrias.
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?