-
Notifications
You must be signed in to change notification settings - Fork 11
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
Constant objects #8
Comments
How do you propose that work with the current API? If I call something like var UserConstants = Marty.createConstants([
"ADD_USER",
"DELETE_USER",
"UPDATE_USER_EMAIL"
]); per the guide, how do I pull out that "User" string? |
I think more I was meaning when you pass an object rather than an array to
Which would result in:
The issue I am trying to avoid is this:
Constants.Users.ADD and Constants.Pages.ADD would result in the same |
ugg sorry, I should have logged into github rather than replying to the email. |
It doesn't really save you much typing to write |
I don't think it's about how much you have to type more about expect behaviour. I had to read the source to convince myself that the constant aren't being created with any sort of name spacing. I'm not really sure what the point of passing a nested object to createConstants if they aren't name spaced. You could just use a flat array and do the name spacing yourself as you suggest. |
Oh, you mean actually passing in an object when you define constants? I misunderstood. I didn't realize that was supported. What you're saying makes sense, then. |
Awesome! sorry if I was confusing. |
If we needed to keep the current API, something like function constants(ns, arr) {
let result = {},
constantsList,
namespace;
if (typeof ns === "string") {
constantsList = arr;
namespace = ns;
}
else if (Array.isArray(ns)) {
constantsList = ns;
namespace = "";
}
else {
throw new Error("The signature for creating constants is ([namespace:string, ] ConstantsList:Array)");
}
constantsList.forEach(function (item) {
let types = [
item,
item + "_STARTING",
item + "_DONE",
item + "_FAILED"
];
types.forEach(function (type) {
result[type] = namespace + type;
});
});
return result;
}
module.exports = constants; would probably work out nicer. |
It's fine as far as it goes, but I think it'd rather move to constants being unique symbols - the problem is that it's technically a breaking change. |
though constants are generated runtime and only exist until the browser is Otherwise you could add an opt-in flag maybe? On 1 July 2015 at 12:59, Jimmy Jia [email protected] wrote:
|
I meant just in case someone was actually taking advantage of how constants map to their string values. Not sure why you'd do this, but it could conceivably break someone. |
Just looking at the constants I'm not sure what the point of using objects to define constants.
Say for example I have { User: ['ADD', 'REMOVE'] } The constants I end up with are basically just 'ADD' and 'REMOVE' which means that I leave my self open to constant collisions if I don't namespace the actual constant key.
Would it make sense to include the 'Path' in the generated constant?
ie { User: ['ADD', 'REMOVE'] } would result in something like 'User__ADD' and 'User__REMOVE'.
You probably make this change without affecting anyones code as you always lookup the values of the constants from the constants list.
The text was updated successfully, but these errors were encountered: