load prettydif from requirejs module

51 views
Skip to first unread message

Gaia

unread,
Mar 2, 2016, 11:13:31 AM3/2/16
to Pretty Diff
Hi,

I would like to load prettydiff to a requirejs module, as follows:

define(["prettydiff"], function (prettydiff) {
"use strict";

...
var settings = {
lang: "xml",
inchar : "\t",
insize: 1,
html: false
};

var content = prettydiff(settings);
....
});


But there is an error of undefined global as currently global object is not shared between the different modules.

Thanks,
Gaia

in...@prettydiff.com

unread,
Mar 2, 2016, 11:18:15 AM3/2/16
to prett...@googlegroups.com
Gaia,

Yeah, just declare an object named global so that the reference is declared.

> define(["prettydiff"], function (prettydiff) {
> "use strict";
>
> ...
> var global = {},
> settings = {
> lang: "xml",
> inchar : "\t",
> insize: 1,
> html: false
> };
>
> var content = prettydiff(settings);
> ....
> });

Thanks,
Austin


Message has been deleted

Gaia

unread,
Mar 3, 2016, 6:15:38 AM3/3/16
to Pretty Diff
Doing so, global is still not defined as it is defined only in the closure it was declared in.
In order to have global defined it should be moved outside of the closure.
I could have it work only as follows:

var global = {};
define([
"prettydiff/lib/csspretty",
"prettydiff/lib/safeSort",
"prettydiff/lib/csvpretty",
"prettydiff/lib/diffview",
"prettydiff/lib/jspretty",
"prettydiff/lib/markuppretty",
"prettydiff/prettydiff"
], function (csspretty, safeSort, csvpretty, diffview, jspretty, markuppretty, prettydiff) {
...
var settings = {


lang: "xml",
inchar : "\t",
insize: 1,
html: false
};
var content = prettydiff(settings);
....
});

Still there are two issues:
1. I would like to avoid global (window scope) variables
2. For our case we do have ace, but prettydiff is not activated from ace.
therefore it conflicts with ace condition in prettydiff.js line 2520:
(ace === undefined || ace.createEditSession === undefined)

Thanks,
Gaia

in...@prettydiff.com

unread,
Mar 3, 2016, 10:27:27 AM3/3/16
to prett...@googlegroups.com
Gaia,

The global object exists a convention for creating modules that is
compatible across the browsers and Node.js. Node.js already provides an
object named global, so I just had to declare a new object in the browser
only code and populate each of these objects in similar ways. I would
also prefer to avoid populating the global scope with additional
references, but this way works universally and doesn't require any
external assets or build process to work.

I am using this code, (ace === undefined || ace.createEditSession ===
undefined), to suppress a conflict in the define function of require.js
because Ace will throw errors about this (even though it still appears to
work). I have just experimented with modifying my instance of Ace so that
it has a property named "prettydiffid" and examining for that instead of
"createEditSession". This appears to successfully suppress the error in
the same way. I will publish this update soon.

Austin
> Doing so, global is still not defined as it is defined only in the closure
> it was declared in.
> In order to have global defined it should be moved outside of the closure.
> I could have it work only as follows:
>
> var global = {};
> define([
> "sap/watt/lib/prettydiff/lib/csspretty",
> "sap/watt/lib/prettydiff/lib/safeSort",
> "sap/watt/lib/prettydiff/lib/csvpretty",
> "sap/watt/lib/prettydiff/lib/diffview",
> "sap/watt/lib/prettydiff/lib/jspretty",
> "sap/watt/lib/prettydiff/lib/markuppretty",
> "sap/watt/lib/prettydiff/prettydiff"
> ], function (csspretty, safeSort, csvpretty, diffview, jspretty,
> markuppretty, prettydiff) {
> ...
> var settings = {
> lang: "xml",
> inchar : "\t",
> insize: 1,
> html: false
> };
>
> var content = prettydiff(settings);
> ....
> });
>
> Still there are two issues:
> 1. I would like to avoid global (window scope) variables
> 2. For our case we do have ace, but prettydiff is not activated from ace.
> therefore it conflicts with ace condition in prettydiff.js line 2520:
> (ace === undefined || ace.createEditSession === undefined)
>
> Thanks,
> Gaia
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Pretty Diff" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pretty-diff...@googlegroups.com.
> To post to this group, send email to prett...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretty-diff/085bc4da-6fe5-47a6-9749-d2e2181b4efc%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


Gaia

unread,
Mar 7, 2016, 12:51:20 AM3/7/16
to Pretty Diff

I understand, Thanks

Gaia

unread,
Mar 7, 2016, 7:51:50 AM3/7/16
to Pretty Diff
On Monday, March 7, 2016 at 7:51:20 AM UTC+2, Gaia wrote:
> I understand, Thanks
In addition I tried to browserify prettydiff, but it do not browserify dependencies and fails loading.
Any recommendations?

in...@prettydiff.com

unread,
Mar 7, 2016, 12:55:00 PM3/7/16
to prett...@googlegroups.com
Gaia,

I have never run Pretty Diff with Browserify, so that is something I will
have to experiment with.

Austin
> --
> You received this message because you are subscribed to the Google Groups
> "Pretty Diff" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pretty-diff...@googlegroups.com.
> To post to this group, send email to prett...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretty-diff/7a7b11c4-60b9-4c18-8ab3-049a8ab7cc57%40googlegroups.com.

Gaia

unread,
Mar 13, 2016, 3:28:30 AM3/13/16
to Pretty Diff
I will appreciate you insights

Thanks,
Gaia

Reply all
Reply to author
Forward
0 new messages