You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@royale.apache.org by Hugo Ferreira <hf...@gmail.com> on 2020/10/02 08:10:46 UTC

2 JS libraries

Hi,

I have 2 JS libraries to inject as externs.
Library 1 has no dependecies.
Library 2 depends on library 1.

If I inject library 1 and then library 2, I get an error on console.

The workaround that I find was:
On my JS injections block:
Add library 1
On window.onload = function() add library 2.

This is thw way to go or there is a better way to do this ?

Re: 2 JS libraries

Posted by Carlos Rovira <ca...@apache.org>.
Hi Hugo,

Until now I didn't have that case. I think all depends on how JS libraries
are done. Some libraries are very well done, while others are a real
nightmare.

In this case the approach I'll try (if possible since I don't know the
internals) is to create a class extern definition per script (or js
"class") and then expose an API in AS3 that handle the integration (if
needed) or just use each one in the right way.

I always try to make JS as OOP as possible by making the externs to have
APIs more near to the AS3 way if possible.

Have that sense?

El vie., 2 oct. 2020 a las 13:26, Hugo Ferreira (<hf...@gmail.com>)
escribió:

>
> ////////////////////////////////////////////////////////////////////////////////
> //
> // Licensed to the Apache Software Foundation (ASF) under one or more
> // contributor license agreements. See the NOTICE file distributed with
> // this work for additional information regarding copyright ownership.
> // The ASF licenses this file to You under the Apache License, Version 2.0
> // (the "License"); you may not use this file except in compliance with
> // the License. You may obtain a copy of the License at
> //
> // http://www.apache.org/licenses/LICENSE-2.0
> //
> // Unless required by applicable law or agreed to in writing, software
> // distributed under the License is distributed on an "AS IS" BASIS,
> // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> // See the License for the specific language governing permissions and
> // limitations under the License.
> //
>
> ////////////////////////////////////////////////////////////////////////////////
> package
> {
> /**
> * @externs
> */
> COMPILE::JS
> public class StimulsoftReports
> {
> /**
> * <inject_script>
> * var script = document.createElement("script");
> * script.setAttribute("src",
> "resources/stimulsoftreports/stimulsoft.reports.js");
> * document.head.appendChild(script);
> * window.onload = function()
> * {
> * var script = document.createElement("script");
> * script.setAttribute("src",
> "resources/stimulsoftreports/stimulsoft.viewer.js");
> * document.head.appendChild(script);
> * }
> * var link = document.createElement("link");
> * link.setAttribute("rel", "stylesheet");
> * link.setAttribute("href",
> "resources/stimulsoftreports/stimulsoft.viewer.office2013.whiteblue.css");
> * document.head.appendChild(link);
> * </inject_script>
> */
> public function StimulsoftReports(){}
>
> public static function loadReport(renderArea:Element,
> reportDefinition:String):void {}
> }
> }
>
> Notice in the example the second library stimulsoft.viewer.js
> This second library depends on the first one so I add this library after
> load.
>
> I don't know if there is a better way or this workaround it's in fact the
> only way.
>
> Another approach maybe is to have a JS that loads this 2 libraries and
> inject this only JS file (I didn't test this theorical approach).
>
> Carlos Rovira <ca...@apache.org> escreveu no dia sexta, 2/10/2020
> à(s) 12:15:
>
> > Hi Hugo,
> >
> > what do you mean with "Inject"? (I guess is not referring to Crux Inject
> > metadata)
> >
> > El vie., 2 oct. 2020 a las 10:11, Hugo Ferreira (<hferreira.80@gmail.com
> >)
> > escribió:
> >
> > > Hi,
> > >
> > > I have 2 JS libraries to inject as externs.
> > > Library 1 has no dependecies.
> > > Library 2 depends on library 1.
> > >
> > > If I inject library 1 and then library 2, I get an error on console.
> > >
> > > The workaround that I find was:
> > > On my JS injections block:
> > > Add library 1
> > > On window.onload = function() add library 2.
> > >
> > > This is thw way to go or there is a better way to do this ?
> > >
> >
> >
> > --
> > Carlos Rovira
> > http://about.me/carlosrovira
> >
>


-- 
Carlos Rovira
http://about.me/carlosrovira

Re: 2 JS libraries

Posted by Hugo Ferreira <hf...@gmail.com>.
////////////////////////////////////////////////////////////////////////////////
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
package
{
/**
* @externs
*/
COMPILE::JS
public class StimulsoftReports
{
/**
* <inject_script>
* var script = document.createElement("script");
* script.setAttribute("src",
"resources/stimulsoftreports/stimulsoft.reports.js");
* document.head.appendChild(script);
* window.onload = function()
* {
* var script = document.createElement("script");
* script.setAttribute("src",
"resources/stimulsoftreports/stimulsoft.viewer.js");
* document.head.appendChild(script);
* }
* var link = document.createElement("link");
* link.setAttribute("rel", "stylesheet");
* link.setAttribute("href",
"resources/stimulsoftreports/stimulsoft.viewer.office2013.whiteblue.css");
* document.head.appendChild(link);
* </inject_script>
*/
public function StimulsoftReports(){}

public static function loadReport(renderArea:Element,
reportDefinition:String):void {}
}
}

Notice in the example the second library stimulsoft.viewer.js
This second library depends on the first one so I add this library after
load.

I don't know if there is a better way or this workaround it's in fact the
only way.

Another approach maybe is to have a JS that loads this 2 libraries and
inject this only JS file (I didn't test this theorical approach).

Carlos Rovira <ca...@apache.org> escreveu no dia sexta, 2/10/2020
à(s) 12:15:

> Hi Hugo,
>
> what do you mean with "Inject"? (I guess is not referring to Crux Inject
> metadata)
>
> El vie., 2 oct. 2020 a las 10:11, Hugo Ferreira (<hf...@gmail.com>)
> escribió:
>
> > Hi,
> >
> > I have 2 JS libraries to inject as externs.
> > Library 1 has no dependecies.
> > Library 2 depends on library 1.
> >
> > If I inject library 1 and then library 2, I get an error on console.
> >
> > The workaround that I find was:
> > On my JS injections block:
> > Add library 1
> > On window.onload = function() add library 2.
> >
> > This is thw way to go or there is a better way to do this ?
> >
>
>
> --
> Carlos Rovira
> http://about.me/carlosrovira
>

Re: 2 JS libraries

Posted by Carlos Rovira <ca...@apache.org>.
Hi Hugo,

what do you mean with "Inject"? (I guess is not referring to Crux Inject
metadata)

El vie., 2 oct. 2020 a las 10:11, Hugo Ferreira (<hf...@gmail.com>)
escribió:

> Hi,
>
> I have 2 JS libraries to inject as externs.
> Library 1 has no dependecies.
> Library 2 depends on library 1.
>
> If I inject library 1 and then library 2, I get an error on console.
>
> The workaround that I find was:
> On my JS injections block:
> Add library 1
> On window.onload = function() add library 2.
>
> This is thw way to go or there is a better way to do this ?
>


-- 
Carlos Rovira
http://about.me/carlosrovira

Re: 2 JS libraries

Posted by Hugo Ferreira <hf...@gmail.com>.
Hi Carlos and Yishay,

Thank you.

Yes, I see that I'm starting with a not easy one but it is what it is and I
need this integration done.
Hope to finish soon and share the code with the community.

Yishay Weiss <yi...@hotmail.com> escreveu no dia sábado, 3/10/2020
à(s) 13:50:

> HI Hugo,
>
> I think you are on the right track. As far as I remember there is no easy
> guaranteed way to serialize code injection in JS.
>
> Yishay
>
> From: Hugo Ferreira<ma...@gmail.com>
> Sent: Friday, October 2, 2020 11:11 AM
> To: Apache Royale Development<ma...@royale.apache.org>
> Subject: 2 JS libraries
>
> Hi,
>
> I have 2 JS libraries to inject as externs.
> Library 1 has no dependecies.
> Library 2 depends on library 1.
>
> If I inject library 1 and then library 2, I get an error on console.
>
> The workaround that I find was:
> On my JS injections block:
> Add library 1
> On window.onload = function() add library 2.
>
> This is thw way to go or there is a better way to do this ?
>
>

RE: 2 JS libraries

Posted by Yishay Weiss <yi...@hotmail.com>.
HI Hugo,

I think you are on the right track. As far as I remember there is no easy guaranteed way to serialize code injection in JS.

Yishay

From: Hugo Ferreira<ma...@gmail.com>
Sent: Friday, October 2, 2020 11:11 AM
To: Apache Royale Development<ma...@royale.apache.org>
Subject: 2 JS libraries

Hi,

I have 2 JS libraries to inject as externs.
Library 1 has no dependecies.
Library 2 depends on library 1.

If I inject library 1 and then library 2, I get an error on console.

The workaround that I find was:
On my JS injections block:
Add library 1
On window.onload = function() add library 2.

This is thw way to go or there is a better way to do this ?