Issue #2181πŸ’¬ AnsweredOpened August 4, 2019by pouyamiralayi2 reactions

Global functions/variables

Quick answerby artf❀ 1

Sorry @pouyamiralayi but I believe you didn't get the total meaning of script property in Component (obviously you're not the only one, even if I try to explain this "script paradox" here) What is asked in #1691 it just DOESN'T MAKE SENSE because the context in script property is like ANOTHER WORLD, the only way to co...

Read full answer below ↓

Question

Hello there! recently i noticed this issue. I think it would be beneficial to have this feature. in contrast to the suggested approach by @artf that uses canvas scripts as a way to inject globally, i think this is not functional for the main purpose that this feature is intended for. in my opinion the main use case for having global variables and functions is the way script is handled inside the canvas: for each component type, it is executing a function every time that canvas is rendered. so if you are registering some sort of handlers for some events in your script, there is no way for you...

Answers (3)

artfβ€’ August 12, 2019

Sorry @pouyamiralayi but I believe you didn't get the total meaning of script property in Component (obviously you're not the only one, even if I try to explain this "script paradox" here) What is asked in #1691 it just DOESN'T MAKE SENSE because the context in script property is like ANOTHER WORLD...

pouyamiralayiβ€’ August 15, 2019

thanks for your kind answer @artf . after struggling with the idea i am reaching to the point that what you are saying is totally reasonable. that was very naive of me to bringing this matter up again sorry for that. the current workaround is completely correct and it's complement the canvas global...

collindutterβ€’ January 20, 2021

@pouyamiralayi would you mind providing some more information on how you created a global event bus to send messages between global scripts and local ones? The editor embeds the grapesjs content in an iframe, so you can't use a global window object as an event bus.

Thanks!

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins β†’
Premium option

Premium plugins ship with support, regular updates, and production-ready features β€” save days of integration work.

Browse premium plugins β†’

Related tutorials

In-depth guides on the same topic.

All tutorials β†’

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.