Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposed refactor of data handling #45

Open
jonschlinkert opened this issue Jan 14, 2017 · 2 comments
Open

proposed refactor of data handling #45

jonschlinkert opened this issue Jan 14, 2017 · 2 comments

Comments

@jonschlinkert
Copy link
Member

This is related to the data bullet in #35.

For the first time in all of my node.js projects, globals are looking like the most appropriate solution. Given that generators are run via command line to scaffold out a new project, versus running a server for a live application or something. In a single session, generate can chain generators and, ideally (and optionally), prevent the same prompt from being presented multiple times by:

  1. caching answers/data throughout the session, and
  2. making this "answer cache" available to all generators, allowing implementors to choose whether or not they want to make use of it. This should be a choice. Implementors can listen (or not) to feedback from users to decide whether or not this makes sense for their generator.

We've tried a few solutions to make sure the data from prompts is always available to all generators, but it hasn't been easy - especially since the code is written to ensure that generators have their own instance (and do not share state). The need for a session answer-cache that is available to all generators consistently seems like as good of a use case for globals as we're likely ever going to have.

Assuming others don't find this completely distasteful, here is how I propose we do it:

  • store the data on a unique namespace on global, like SOME_LONG_ANSWER_CACHE_NAME
  • provide methods for getting and setting, like app.global.set(), app.global.get() etc. These would of course also support object paths, like app.global.get('foo.bar.baz'). We could also have a .merge() method or something, so that data from generators could be stored separately until it's needed, at which time it would be cloned and merged.

I'm open to any alternatives, opinions, suggestions or pushback...

Any thoughts @doowb @stefanwalther @tunnckoCore @dawsonbotsford or others?

@tunnckoCore
Copy link

tunnckoCore commented Jan 14, 2017

store the data on a unique namespace on global

Why not just save it at base instance instead of at file system or global?

I mean, we already have access to the very base instance from plugins/generators.

and they do not share state

We have app, base signature in the plugins/generators?

What about

app.use(function (app, base) {})

provide methods for getting and setting

If you choose global, it again would be easy to implement.

@jonschlinkert
Copy link
Member Author

Why not just save it at base instance instead of at file system or global?

That's what we're doing currently, this was always my preference. I'll try to see if I can figure out why it's not working in some situations. We might be able to solve this issue simply by enforcing a convention for how data is cached after an answer is given.

actually... I might be able to do something with enquirer to make this easier without adding magic. after I play around with that I'll report back

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants