Create re-usable js library?

69 views
Skip to first unread message

simo

unread,
Mar 10, 2013, 10:05:08 AM3/10/13
to haxe...@googlegroups.com

I would like to know as I am targeting javascript, how can I create a re-usable library of my own code, that I can use in multi js haxe projects?
I have an HTML5 based viewer which depends on a presentation-logic, what I want to do, is to isolate the presentation logic into a library, 
and then use multiple views in the same html page all referencing the same presentation-logic js library.

I think to start with the library by creating a presentation js haxe project, where I will put my re-usable classes, but, what to do next?
Any idea?

Postite

unread,
Mar 10, 2013, 11:02:41 AM3/10/13
to haxe...@googlegroups.com
Why don't you Create an haxelib of your own classes ! 
Then install it with haxelib dev.
Look at Mlib to generate a quick and evolutive haxelib !
--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Michel Romecki

unread,
Mar 10, 2013, 11:22:31 AM3/10/13
to haxe...@googlegroups.com

Samir Sabri

unread,
Mar 11, 2013, 2:06:56 AM3/11/13
to haxe...@googlegroups.com
@Michel Yes, that's exactly what I want, thank you, @David I can't create a haxelib, as I am writing a private library which I believe will make me rich! ;-)

You received this message because you are subscribed to a topic in the Google Groups "Haxe" group.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
--
Kind Regards,
--------------------------------------------- 
Samir Sabri
Software Architect& Developer
Jordan-Middle East

Samir Sabri

unread,
Mar 11, 2013, 2:20:11 AM3/11/13
to haxe...@googlegroups.com
Can any one please provide a link where I can read about @:native and @:expose ?

Baluta Cristian

unread,
Mar 11, 2013, 2:28:50 AM3/11/13
to haxe...@googlegroups.com
You can install the haxelib only for yourself with haxelib test. What i actually do is having a blank haxelib installed then point it to my development version.

Samir Sabri

unread,
Mar 11, 2013, 2:33:18 AM3/11/13
to haxe...@googlegroups.com
Thanks Baluta, but I am newbie to haxe, can you describe your approach step by step? or a simple tutorial? I really appreciate it.

Baluta Cristian

unread,
Mar 11, 2013, 3:01:28 AM3/11/13
to haxe...@googlegroups.com
1. Create a haxelib after this specifications http://haxe.org/doc/haxelib/using_haxelib
2. install it with 'haxelib test <zip-file>'
3. link it with your project with the '-lib haxelibname'
4. Now if you want to edit it and see the effects immediately you have 2 choices:
4.1 go to the haxelib directory and find your lib and edit it there
4.2 you can tell haxelib to use the development version instead the one that's installed. Run 'haxelib dev <haxelibname> <path-to-dev-version-folder>

Samir Sabri

unread,
Mar 11, 2013, 3:15:51 AM3/11/13
to haxe...@googlegroups.com
Thanks Baluta for details, 
I want to be able to reference the haxelib compiled code in run time, as I will have several viewers on the same html page that depends on my haxelib.

For example, in the HTML page, I will have something like this:

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<canvas id="viewer" width="600" height="300"></canvas>
<script src="http://mydomain.com/my_viewer.min.js"></script>
</body>
</html>

So, would my haxelib code get excluded from the project compiled js code?

Samir Sabri

unread,
Mar 21, 2013, 5:45:34 AM3/21/13
to haxe...@googlegroups.com
I figured it out, I will create three haxe projects:

1. the shared library, which will be exposed to main app
2. the shared library extern which will be a haxelib, for those who is new to haxe, this is the glue for the external shared library, define those methods that I will be using ..
3. the main app, which will reference the haxelib

then I will put a compiled js file of the first project (the shared library) next to the compiled js file of the main project
in html file:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>SharedLibConsumer</title>
<meta name="description" content="" />
<script src="HaxeLibTest.js"></script>
</head>
<body>
<div id="haxe:trace"></div>
<script src="SharedLibConsumer.js"></script>
</body>
</html>

very nice .. :-)
Reply all
Reply to author
Forward
0 new messages