Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

fix: be compatible with the latest minim #481

Merged
merged 6 commits into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Components/Attributes/Attributes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import abagnale from 'abagnale/lib/abagnale';
import cloneDeep from 'lodash/cloneDeep';
import eidolon from 'eidolon';
import JSON06Serialiser from 'minim/lib/serialisers/json-0.6';
import { JSON06Serialiser } from 'minim';
ajkl2533 marked this conversation as resolved.
Show resolved Hide resolved
import { EventEmitter } from 'fbemitter';
import isUndefined from 'lodash/isUndefined';
import isArray from 'lodash/isArray';
Expand Down
19 changes: 8 additions & 11 deletions src/Components/Attributes/test/Attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,11 @@ describe('Attributes', () => {
const minimNamespace = minim.namespace().use(minimParseResult);
const Category = minimNamespace.getElementClass('category');
const DataStructure = minimNamespace.getElementClass('dataStructure');
const Element = minimNamespace.getElementClass('element');
const ReferenceElement = Element.extend({
/* eslint-disable object-shorthand */
constructor: function (ref) {
Element.apply(this, arguments); // eslint-disable-line prefer-rest-params
this.element = ref.toValue();
},
});
const createReferenceElement = function createReferenceElement(ref) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should investigate why we see the Uncaught TypeError: Class constructor cannot be invoked without 'new'when trying to use class ReferenceElement extends Element {...}`

// cc @kylef

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the RefElement from minim itself?

You can use element.toRef() to create a reference element from another element.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was following the format fury.parse returns which is { "element": "Address" }. I have never found the 'ref' element in there. Is that equivalent?

Copy link
Member

@kylef kylef Feb 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, there are two types of references. There is "ref" element, which is used under some circumstances and then there is placing the id of the target element as your element name which. I though the ReferenceElement here was the same thing as our RefElement.

What is the code with class ReferenceElement extends Element that isn't working?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I do this:

const ReferenceElement = class ReferenceElement extends Element {
      constructor(ref) {
        super(ref);

        this.element = ref.toValue();
      }
};

I'll get:

TypeError: Class constructor Element cannot be invoked without 'new'
    at new ReferenceElement (/Users/radekpodrazky/Documents/PROJECTS/attributes-kit/src/Components/Attributes/test/Attributes.js:50:24)
    at Suite.<anonymous> (/Users/radekpodrazky/Documents/PROJECTS/attributes-kit/src/Components/Attributes/test/Attributes.js:64:16)
    at Object.create (/Users/radekpodrazky/Documents/PROJECTS/attributes-kit/node_modules/mocha/lib/interfaces/common.js:114:19)
    at context.describe.context.context (/Users/radekpodrazky/Documents/PROJECTS/attributes-kit/node_modules/mocha/lib/interfaces/bdd.js:44:27)
    at Suite.<anonymous> (/Users/radekpodrazky/Documents/PROJECTS/attributes-kit/src/Components/Attributes/test/Attributes.js:40:3)
    at Object.create (/Users/radekpodrazky/Documents/PROJECTS/attributes-kit/node_modules/mocha/lib/interfaces/common.js:114:19)
    at context.describe.context.context (/Users/radekpodrazky/Documents/PROJECTS/attributes-kit/node_modules/mocha/lib/interfaces/bdd.js:44:27)
    at Object.<anonymous> (/Users/radekpodrazky/Documents/PROJECTS/attributes-kit/src/Components/Attributes/test/Attributes.js:9:1)
    at Module._compile (module.js:652:30)
    at loader (/Users/radekpodrazky/Documents/PROJECTS/attributes-kit/node_modules/babel-register/lib/node.js:144:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/radekpodrazky/Documents/PROJECTS/attributes-kit/node_modules/babel-register/lib/node.js:154:7)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at /Users/radekpodrazky/Documents/PROJECTS/attributes-kit/node_modules/mocha/lib/mocha.js:231:27
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/Users/radekpodrazky/Documents/PROJECTS/attributes-kit/node_modules/mocha/lib/mocha.js:228:14)
    at Mocha.run (/Users/radekpodrazky/Documents/PROJECTS/attributes-kit/node_modules/mocha/lib/mocha.js:514:10)
    at Object.<anonymous> (/Users/radekpodrazky/Documents/PROJECTS/attributes-kit/node_modules/mocha/bin/_mocha:480:18)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeError: Class constructor Element cannot be invoked without 'new'

I think this is caused by the transpilation introduced in this project, for some reason "Element" is a function and thus you can't new or super it. Take the following example:

$ node example.js
ReferenceElement {
  _content: StringElement { _content: 'User', _storedElement: 'string' },
  _storedElement: 'User' }

$ cat example.js
const { Element, refract } = require('minim');

class ReferenceElement extends Element {
  constructor(ref) {
    super(ref);
    this.element = ref.toValue();
  }
};

const ref = new ReferenceElement(refract('User'));
console.log(ref);

const element = new minim.Element();
element.element = ref.toValue();
return element;
};

const addressObject = new minim.ObjectElement({
street: 'Main St.',
Expand All @@ -57,14 +54,14 @@ describe('Attributes', () => {
}, { id: 'Address' });
const userObject = new minim.ObjectElement({
name: 'Doe',
address: new ReferenceElement(addressObject.id),
address: createReferenceElement(addressObject.id),
}, { id: 'User' });

const dataStructures = new Category(
new minim.ArrayElement([
opichals marked this conversation as resolved.
Show resolved Hide resolved
[
new DataStructure(userObject),
new DataStructure(addressObject),
]),
],
{ classes: ['dataStructures'] }
);

Expand Down