mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 16:29:34 +00:00
Add components API
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
a38c6738e1
commit
d512043b12
36
packages/strapi-admin/admin/src/utils/ComponentApi.js
Normal file
36
packages/strapi-admin/admin/src/utils/ComponentApi.js
Normal file
@ -0,0 +1,36 @@
|
||||
import { cloneDeep } from 'lodash';
|
||||
import invariant from 'invariant';
|
||||
|
||||
class ComponentApi {
|
||||
components = {};
|
||||
|
||||
getComponent = name => {
|
||||
invariant(name, 'A name must be provided');
|
||||
|
||||
return cloneDeep(this.components[name]) || null;
|
||||
};
|
||||
|
||||
getComponents = () => {
|
||||
return cloneDeep(this.components);
|
||||
};
|
||||
|
||||
registerComponent = component => {
|
||||
const { name, Component } = component;
|
||||
|
||||
invariant(Component, 'A Component must be provided');
|
||||
invariant(name, 'A name must be provided');
|
||||
invariant(this.components[name] === undefined, 'A similar field already exists');
|
||||
|
||||
this.components[name] = Component;
|
||||
};
|
||||
|
||||
removeComponent = name => {
|
||||
invariant(name, 'A name must be provided in order to remove a field');
|
||||
|
||||
delete this.components[name];
|
||||
};
|
||||
}
|
||||
|
||||
export default () => {
|
||||
return new ComponentApi();
|
||||
};
|
@ -1,6 +1,9 @@
|
||||
import ComponentApi from './ComponentApi';
|
||||
import FieldApi from './FieldApi';
|
||||
|
||||
class Strapi {
|
||||
componentApi = ComponentApi();
|
||||
|
||||
fieldApi = FieldApi();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user