-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable manual initialization via global flag
- Loading branch information
Showing
6 changed files
with
41 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,22 @@ | ||
/** | ||
* This module provides a self-initializing CMS instance with API hooks added to | ||
* the `window` object. | ||
*/ | ||
import React from 'react'; | ||
import bootstrap, { ROOT_ID } from './bootstrap'; | ||
import bootstrap from './bootstrap'; | ||
import registry from 'Lib/registry'; | ||
import createReactClass from 'create-react-class'; | ||
|
||
let initialized = false; | ||
|
||
/** | ||
* Allow init of the CMS. | ||
* Load Netlify CMS automatically if `window.NC_MANUAL_INIT` is set. | ||
*/ | ||
function init(opts = {}) { | ||
if (initialized) { | ||
console.error('Bootstrap attempted, but Netlify CMS is already initialized!'); | ||
return; | ||
} | ||
initialized = bootstrap(opts); | ||
return initialized; | ||
if (!window.NC_MANUAL_INIT) { | ||
bootstrap(); | ||
} | ||
|
||
/** | ||
* Allow reset of the CMS to allow render after unmount | ||
* Add extension hooks to global scope. | ||
*/ | ||
function reset() { | ||
initialized = false; | ||
if (typeof window !== 'undefined') { | ||
window.CMS = registry; | ||
window.createClass = window.createClass || createReactClass; | ||
window.h = window.h || React.createElement; | ||
} | ||
|
||
const CMS = (function startApp() { | ||
/** | ||
* Load the app, bail if root element exists or no-auto element. | ||
* Use <div id="no-auto" /> in your app if you are not persisting the root element. | ||
* (in example: as a React Route) | ||
*/ | ||
if (document.getElementById('no-auto') || document.getElementById(ROOT_ID)) { | ||
console.log('CMS is running in manual mode. [using init() to initialize]'); | ||
} else { | ||
init(); | ||
} | ||
|
||
/** | ||
* Add extension hooks to global scope. | ||
*/ | ||
const api = { init, reset, ...registry }; | ||
if (typeof window !== 'undefined') { | ||
window.CMS = api; | ||
window.createClass = window.createClass || createReactClass; | ||
window.h = window.h || React.createElement; | ||
} | ||
return api; | ||
})() | ||
|
||
/** | ||
* Export the registry for projects that import the CMS. | ||
*/ | ||
export default CMS; | ||
|
||
/** | ||
* Export the init, reset and registry standalone. (optional) | ||
*/ | ||
export { init, reset, registry }; | ||
export { registry as default, bootstrap as init }; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters