Skip to content
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

this.get(...).each is not a function #724

Closed
kickbk opened this issue Jan 5, 2018 · 8 comments
Closed

this.get(...).each is not a function #724

kickbk opened this issue Jan 5, 2018 · 8 comments
Labels

Comments

@kickbk
Copy link

kickbk commented Jan 5, 2018

Getting this.get(...).each is not a function with the latest 0.12.58 version (cdn min.js).
The line that triggers it is return this.get("classes").each(function(e){return t.push(e.get("name"))})

@NicholasGati
Copy link

Just wondering, does this.get(...) return an array? If not, maybe you can try this:

const c = this.get("classes");
Array.from(c).forEach(e => t.push(e.get("name")));

Not sure if that's what the issue is but I figured I'd chime in and try to help :)

@ryandeba
Copy link
Contributor

ryandeba commented Jan 7, 2018

Hi @kickbk,

It is unclear what this is bound to in your code...is that a reference to a component? If you could create a jsfiddle to demonstrate the error, that would be very helpful.

I've not been able to recreate the error so far. I ran this code in the demo (which also currently uses version 0.12.58) after selecting a random component and it worked without errors:
t = []; editor.getSelected().get("classes").each(function(e) { t.push(e.get("name")) })

@kickbk
Copy link
Author

kickbk commented Jan 7, 2018

Thanks for replying guys. I traced the issue to my custom components' Traits.
What's triggering it is that I load default values for traits:

export default (editor, {
	dc, opt, defaultModel, defaultView, coreMjmlModel, coreMjmlView
}) => {
	const type = 'mj-my-component';
  
	dc.addType(type, {

		model: defaultModel.extend({ ...coreMjmlModel,

			defaults: { ...defaultModel.prototype.defaults,
				'custom-name': 'Footer',
				draggable: '[data-type=mj-column]',
				droppable: false,
				stylable: [...],
				style: {...},
				traits: [
					{
						name: 'organization-content',
						label: 'Organization Name',
						default: 'TEST', // << HERE IS THE ISSUE
					},{...}
				],
...

As you can see my plugin extends on grapesjs-mjml.

Changing default to value gives the same error.

Is this the wrong way to load defaults to traits?

@artf
Copy link
Member

artf commented Jan 8, 2018

Hi @kickbk and thanks for the debugging, I was able to reproduce it and fix it.
The issue was the loading of Traits before Classes
https://github.com/artf/grapesjs/blob/dev/src/dom_components/model/Component.js#L167-L168
The fix is ready and will be available in the next release

@kickbk
Copy link
Author

kickbk commented Jan 8, 2018

Hi @artf glad you found the cause and fixed. It's causing your grapesjs-mjml to fail, like the demo page which doesn't load. Is this issue related to the Traits default value overriding chosen values when updating styles? See GrapesJS/mjml#50

@artf
Copy link
Member

artf commented Jan 8, 2018

Yeap, I updated the site with a temporary release, thanks

@kickbk
Copy link
Author

kickbk commented Jan 9, 2018

@artf thanks for pushing a temporary release. It's still running into issues with the Social component in mjml. Steps to reproduce: add "google" to the "display" string. Click on the Styles tab, select an icon color for Facebook and watch the Google button disappear.

I debugged this and for some reason when you update styles (handleStyleChange()) it loads the default trait/style value disregarding the trait updated value, so in the case of "display" it reverts to the default set in Social.js under components.

I spent a few hours on it and still can't pinpoint the issue.

BTW "style-default" doesn't really work. Changing to "style" bring shows the default icon colors.

@artf artf closed this as completed in 5240c19 Jan 9, 2018
@lock
Copy link

lock bot commented Sep 18, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot added the outdated label Sep 18, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Sep 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants