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

Context variable passed through to FromDoc and PostDoc functions #8

Open
rdw opened this issue Mar 31, 2017 · 6 comments
Open

Context variable passed through to FromDoc and PostDoc functions #8

rdw opened this issue Mar 31, 2017 · 6 comments
Labels
📈enhancement A useful improvement or extension to existing behavior 💡 idea

Comments

@rdw
Copy link
Contributor

rdw commented Mar 31, 2017

Throwing this idea out there for comments.

One of the use cases we have is essentially cross-referencing different databases of config objects. So we'll have an item which declares some gun mounts, and those have to be registered in a gun database (because we also have guns declared on their own, too). Or we have a player class that declares its default secondary fire, which we want to look up from a database when we load the class (arguably, we don't have to do that but we are right now, so....).

It would help with this if we had access to these databases inside the FromDoc functions (or PostDoc, but we don't actually have many of those). So one way to do this would be to pass in a Context object, and the caller of Apply or Reify could supply an object to stick on there, which FromDocs could retrieve.

@rdw rdw added 📈enhancement A useful improvement or extension to existing behavior help wanted and removed help wanted labels Mar 31, 2017
@tenpn
Copy link
Contributor

tenpn commented Mar 31, 2017

Love it. Always a fan of reducing singletons and making things more testable.

Would it be too much of a mess to template it? Sooo Config.Apply<List<Gun>, BulletDB>("guns", ref gunList, myBulletDB)? (assuming we could emit the params in practice) It almost certainly would penetrate too many functions to be practical?

Also I didn't even know about postdoc???

@tenpn
Copy link
Contributor

tenpn commented Mar 31, 2017

(it'd be optional right?)

@rdw
Copy link
Contributor Author

rdw commented Mar 31, 2017

Thanks for the thoughts! Yes, I think it would have to be optional. Most of the time it would be unused.

Templating is interesting; the FromDoc function gets called through reflection so it probably wouldn't be too much modification. What would it do if types didn't match, though? It seems infeasible to detect such things at compile time so it'd probably throw an InvalidCastException.

@rdw
Copy link
Contributor Author

rdw commented Mar 31, 2017

Actually, I guess the worst case scenario would be reifying a heterogeneous assortment of classes, each of which expects a different context type. It'd suck to have to work around that. Maybe the right solution is to null out context arguments where the type isn't assignable, and all FromDocs have to assume that their context can be null. (and of course it can't be a value type because what is the point of that)

@rdw
Copy link
Contributor Author

rdw commented Mar 31, 2017

The history of DarkConfig is me saying "I won't need a value type in this use case.... wait, dang."

@tenpn
Copy link
Contributor

tenpn commented Mar 31, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📈enhancement A useful improvement or extension to existing behavior 💡 idea
Projects
None yet
Development

No branches or pull requests

3 participants