Browse Source

Fix definitions process with circular structures

pull/2295/head
Artur Arseniev 6 years ago
parent
commit
e85cfd1db6
  1. 18
      src/dom_components/model/Components.js
  2. 15
      test/specs/dom_components/model/Component.js

18
src/dom_components/model/Components.js

@ -84,18 +84,24 @@ export default Backbone.Collection.extend({
* Process component definition.
*/
processDef(mdl) {
// Avoid processing Models
if (mdl.cid && mdl.ccid) return mdl;
const { em, config = {} } = this;
const { processor } = config;
let model = { ...mdl }; // Avoid 'Cannot delete property ...'
const modelPr = processor && processor(model);
if (modelPr) {
each(model, (val, key) => delete model[key]);
extend(model, modelPr);
let model = mdl;
if (processor) {
model = { ...model }; // Avoid 'Cannot delete property ...'
const modelPr = processor(model);
if (modelPr) {
each(model, (val, key) => delete model[key]);
extend(model, modelPr);
}
}
// React JSX preset
if (model.$$typeof && typeof model.props == 'object') {
model = { ...model };
model.props = { ...model.props };
const domc = em.get('DomComponents');
const parser = em.get('Parser');

15
test/specs/dom_components/model/Component.js

@ -330,6 +330,21 @@ module.exports = {
expect(child.get('propagate')).toEqual(['removable']);
});
// This will try to avoid, eventually, issues with circular structures
test('Can stringify object after edits', () => {
const added = dcomp.addComponent(`
<div>
<div>Comp 1</div>
<div>Comp 2</div>
<div>Comp 3</div>
</div>
`);
const comp1 = added.components().at(0);
comp1.remove();
added.append(comp1);
expect(JSON.stringify(added)).toBeTruthy();
});
test('Guarantee the uniqueness of components ids', () => {
const idName = 'test';
const added = dcomp.addComponent(`

Loading…
Cancel
Save