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

WIP: Rename the global define function, plip #1529 #1707

Closed
wants to merge 1 commit into from
Closed

Conversation

vangheem
Copy link
Member

@vangheem vangheem commented Aug 7, 2016

To implement plip: #1529

@rnixx
Copy link
Member

rnixx commented Sep 23, 2016

You simply reset global define AFTER ALL registered resource bundles have been delivered, right?
But then it does not solve our basic problem.

E.g.

https://github.com/collective/collective.js.datatables/blob/master/collective/js/datatables/profiles/plone5/registry.xml <- the JS is delivered as bundle as well...

So to make it work right now we implemented a really bad hack -> https://github.com/collective/collective.js.datatables/blob/master/collective/js/datatables/resources/media/js/jquery.dataTables.min.js#L5

define and require gets unset before the actual script is loaded and then reset to the original values -> https://github.com/collective/collective.js.datatables/blob/master/collective/js/datatables/resources/media/js/jquery.dataTables.min.js#L175

That's why I was suggesting to implement a (generated) wrapper around each bundle if desired (except the basic JS, after which define and require should be reset) as described here -> #1529 (comment)

Or do I miss something in your approach?

@rnixx
Copy link
Member

rnixx commented Sep 23, 2016

So in order to achieve the flexibility with bundles, merged in one file or not, delivered JS structure may look somthing like:

// jquery as is
...

// requirejs as is
...

// reset define and require

plone_define = define;
plone_require = require;
define = undefined;
require = undefined;

// iterate registered bundle resources

(function(define, require) { // generated wrapper if defined for bundle in registry (default true)
  require([
    'mockup-pattern-autotoc'
  ], function(AutoTOC){
    // something
  });
})(plone_define, plone_require); // generated wrapper

// if no generated wrapper deliver JS as is

// all bundles delivered with addons
...

@vangheem
Copy link
Member Author

vangheem commented Oct 22, 2016

@rnixx datatables is a unique case where the packaging is exceptionally difficult and not compatible. If you're packaging inside a bundle with requirejs, there is nothing else, no magic, we can do. Some js packages just suck to work with in packaging.

This PR is only to help those that have trouble including js from manual <script> tags or from inside their theme for example.

@vangheem
Copy link
Member Author

@vangheem vangheem changed the title Rename the global define function, plip #1529 WIP: Rename the global define function, plip #1529 Oct 22, 2016
@vangheem
Copy link
Member Author

This doesn't always work quite as expected as it can mess with other bundling in other unexpected ways.

I'm putting this PR on hold for now until we can figure out if there is a more safe way.

@vangheem vangheem closed this Jun 27, 2017
@jensens jensens deleted the plip-1529 branch April 3, 2018 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants