-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Register Internal and Custom backend API's #1011
Conversation
Deploy preview for netlify-cms-www ready! Built with commit dd3a364 |
Deploy preview for cms-demo ready! Built with commit dd3a364 |
src/lib/registry.js
Outdated
/** | ||
* Backend API | ||
*/ | ||
export function registerBackends(name, BackendClass) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be singular, since you are only registering one backend at a time (with each function call). For example, we have registerWidget
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought so too 👍 of course, after I changed it 😄 [Changed Back!]
console.error(`Backend [${ name }] already registered. Please choose a different name.`); | ||
} else { | ||
registry.backends[name] = { | ||
init: config => new BackendClass(config), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still wonder why we shouldn't just do
registry.backends[name] = BackendClass;
and then in the backend code
const UserBackend = getBackend(name);
return new Backend(new UserBackend(config), name, authStore);
Can you explain? Just cleaner?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coder preference, I like the object reference is all. Kept it the way it was.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking initiative on this @talves, I love how simple of a first step this is!
Regarding this piece of code, we want project style to trump an individual developer's preference - no reason to make this function different than the others. Let's update this registry function to simply assign the registered entity as Caleb suggested.
After that, should be good to merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine either way, it's pretty much just bikeshedding IMO. Do we have a reason that it should be one way or another?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be different if we weren't committing to this decision as a part of our public API, which we can't break until 2.0 once merged. We should be in agreement before proceeding - let's feature flag it for now and get some mileage on it before making it public.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like Tony said, this specific discussion is just about code style -- it doesn't impact the public API at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On not breaking the public API, though, I'm fine with putting it in a beta/flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, this does not impact the public API, I stand corrected 🤦♂️
src/backends/backend.js
Outdated
*/ | ||
registerBackends('git-gateway', GitGatewayBackend); | ||
registerBackends('github', GitHubBackend); | ||
registerBackends('test-repo', TestRepoBackend); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
Created an example backend library here (might look familiar to some of you) |
Discussion on handling dependencies in Gitter (January 15, 2018 4:34 PM):
|
console.error(`Backend [${ name }] already registered. Please choose a different name.`); | ||
} else { | ||
registry.backends[name] = { | ||
init: config => new BackendClass(config), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking initiative on this @talves, I love how simple of a first step this is!
Regarding this piece of code, we want project style to trump an individual developer's preference - no reason to make this function different than the others. Let's update this registry function to simply assign the registered entity as Caleb suggested.
After that, should be good to merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
- Summary
A solution to register a custom backend API while also registering the internal API's so there is no overwriting of names.
The backends internally target
github
and thegit-gateway
without any changes to the CMS itself. This solution is a non breaking solution for the current CMS without having to change the internal backend's.- Test plan
Make sure the CMS works as is using all current internal backends.
Test a custom created backend by registering the new backend
CMS.registerBackends("my-custom-backend", MyCustomBackendClass)
Created an example backend library here (might look familiar to some of you)
- Description for the changelog
Register Internal and Custom backend API's
- A picture of a cute animal (not mandatory but encouraged)
🐶