GithubHelp home page GithubHelp logo

massive-oss / mloader Goto Github PK

View Code? Open in Web Editor NEW
33.0 91.0 14.0 4.98 MB

A cross platform Haxe library for loading resources with utilities for queueing and caching requests. Supports AVM2, JavaScript, Neko and C++.

Home Page: open.massiveinteractive.com

License: MIT License

Haxe 99.76% HTML 0.24%

mloader's Introduction

Overview

MLoader is a cross platform Haxe library for loading resources with utilities for queueing and caching requests. Supports AVM2, JavaScript, Neko and C++.

  • Signal based notification of loading events and errors
  • Leverages type parameters to type loaded content
  • Utilities for caching and queuing loaders
  • Supports local urls in Neko

Note: MassiveLoader includes a patch to haxe.Http to enable abortable Http requests. The patch is clearly documented in haxe/Http.hx

Installation

Install mloader from haxelib:

haxelib install mloader

Or if you want to install the latest directly from github:

haxelib git mloader https://github.com/massiveinteractive/mloader.git src/lib

And to point to your local fork:

haxelib dev mloader /ABSOLUTE_PATH_TO_REPO/src/lib

Basic Usage

You can download an more comprehensive cross platform example project here.

To load a string:

import mloader.Loader;

class Main
{
	public static function main()
	{
		var loader = new mloader.StringLoader("something.txt");
		loader.loaded.add(onLoaded);
		loader.load();
	}

	static function onLoaded(event:LoaderEvent<String>)
	{
		switch (event.type)
		{
			case Complete: trace(event.target.content);
			case Fail(e): trace("Loader failed: " + e);
		}
	}
}

You can also listen for specific events using msignal's forType method:

loader.loaded.add(onComplete).forType(Complete);

XmlLoader and JsonLoader will attempt to parse the response:

import mloader.Loader;

class Main
{
	public static function main()
	{
		var loader = new mloader.XmlLoader("something.xml");
		loader.loaded.add(onLoaded);
		loader.load();
	}

	static function onLoaded(event:LoaderEvent<Xml>)
	{
		switch (event.type)
		{
			case Complete:
				trace(event.target.content.firstElement());

			case Fail(e):
				switch (e)
				{
					case Format(info): trace("Could not parse Xml: " + info);
					case IO(info): trace("URL could not be reached: " + info);
					default: trace(e);
				}
		}
	}
}

LoaderQueue will sequentially load a list of loaders:

import mloader.Loader;
import mloader.LoaderQueue;
import mloader.ImageLoader;
import mloader.JsonLoader;

class Main
{
	public static function main()
	{
		var queue = new LoaderQueue();
		queue.maxLoading = 2; // max concurrent
		queue.ignoreFailures = false; // carry on regardless
		queue.loaded.addOnce(queueComplete).forType(Complete);

		var json = new JsonLoader("data.json");
		json.loaded.addOnce(jsonComplete).forType(Complete);

		queue.add(new ImageLoader("image-01.jpg"));
		queue.add(new ImageLoader("image-02.jpg"));
		queue.add(new ImageLoader("image-03.jpg"));
		queue.add(new ImageLoader("image-04.jpg"));
		queue.addWithPriority(jsonLoader, 1); // load first

		// start the queue
		queue.load();
	}
}

function queueComplete(event:LoaderEvent<Dynamic>)
{
	trace("LoaderQueue completed!");
}

function jsonComplete(event:LoaderEvent<Dynamic>)
{
	trace("JSON data loaded " + Std.string(event.target.content));
}

Documentation

The API documentation is available on the haxelib project page.

Or you can just read through the source ;)

How to contribute

If you find a bug, report it.

If you want to help, fork it.

If you want to make sure it works, install munit so you can run the test suite from the project root:

haxelib run munit test -js -as3 -neko

Credits

This project is brought to you by David and Mike from Massive Interactive

mloader's People

Contributors

dpeek avatar elsassph avatar kuremu avatar mikestead avatar misprintt avatar redrum avatar richard-walton avatar zhaoterryy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mloader's Issues

Error when using hxnodejs - works fine without hxnodejs (in Electron)

When I add the library hxnodejs to my compile, even if I don't specifically target any classes Electron will throw the following runtime error after calling LoaderQueue.load(); - This call is happening in the Renderer module - not the main module.

If I remove the library from compile, everything works as expected.

events.js:182 Uncaught Error: socket hang up at createHangUpError (_http_client.js:345) at Socket.socketCloseListener (_http_client.js:377) at emitOne (events.js:120) at Socket.emit (events.js:210) at TCP._handle.close [as _onclose] (net.js:549)

OpenFL: XmlLoader can't find files at runtime

Hi, i have been trying to use mloader with OpenFL, however, the loader does not find any assets at runtime. Example (file tree):

/bin
    application.swf
    asset.xml

Trying to load asset.xml:

var loader = new XmlLoader("asset.xml");
loader.loaded.add(onLoaded);
loader.load();

Returns this error:

Assets.hx:220: [openfl.Assets] There is no String or ByteArray asset with an ID of "asset.xml"

I know it works if i put the asset.xml file inside OpenFL's asset folder, but doesn't it defeat the whole purpose of using a loader?

I'm using the latest version of the libs from Haxelib: OpenFL (1.0.6), mloader (2.2.0), Haxe (3.0.0).

Sorry about posting this as an issue (this may well be a misuse of the lib on my part), but there is no other place to post questions or comments about the library.

Thanks!

Suggestion - Retry On Error

It would be cool if there was a retry on error feature. There are a few ways this could be implemented such as a maxRetries property of the loader. A signal would be good too so the user can tell when a retry occurs.

Using xmlLoader.parseData property supresses errors in the browser

If you set the parseData property then all subsequent errors in the browser do not get output to the console. The following example does the trick

static function main() 
{
    var a:Array<Int> = null;        

    var queue = new LoaderQueue();

    queue.maxLoading = 2; // max concurrent
    queue.ignoreFailures = true; // carry on regardless
    queue.loaded.add(function(event:LoaderEvent<Dynamic>):Void {            
        trace("Loaded");
        a.push(3);//This will not output a runtime error
    }).forType(Complete);

    var xmlLoader = new XmlLoader("xml/project.xml");
    xmlLoader.parseData = function( xmlData:Xml):Xml {          
        return xmlData;
    }

    queue.add( xmlLoader );     
    queue.load();

    a.push(10); //This generates an error as expected
}

mloader API doc missing. Autocompletion in FlashDevelop not working

Hi,
First I want to say I'm loving your framework.
I have some complaints though ;P
API documentation it's not in haxelib as stated in the github overviow of your projects. Perhaps it's a haxelib.org problem, I don't know.
Anyway there are problems also in Flashdevelop with the autocompletion:

I just installed it with
haxelib install mloader

Downloading mloader-2,0,2.zip...
Download complete : 28587 bytes in 0.1s (149.2KB/s)
Install LICENSE
Install haxelib.json
Install haxelib.xml
Created mloader/
Install mloader/Http.hx
Install mloader/HttpLoader.hx
Install mloader/HttpMock.hx
Install mloader/ImageLoader.hx
Install mloader/JsonLoader.hx
Install mloader/Loader.hx
Install mloader/LoaderBase.hx
Install mloader/LoaderCache.hx
Install mloader/LoaderQueue.hx
Install mloader/StringLoader.hx
Install mloader/SwfLoader.hx
Install mloader/XmlLoader.hx
Install mloader/XmlObjectLoader.hx
Install mloader/XmlObjectParser.hx
Current version is now 2.0.2
Done
Installing dependency msignal
Downloading msignal-1,2,1.zip...
Download complete : 11965 bytes in 0s (120.4KB/s)
Install haxelib.json
Install haxelib.xml
Install LICENSE
Created msignal/
Install msignal/EventSignal.hx
Install msignal/Signal.hx
Install msignal/Slot.hx
Install msignal/SlotList.hx
Current version is now 1.2.1
Done

I'm trying to use itn on and openfl projec on FD 4.4.3(R27224)
But no auto completion at all. It doesn't show up in the imported library on the Project panel, though it adds msignals to it (cause it depends on it)

iterate through xml children?

I tried to iterate though children of loaded xml:

var xml = event.target.content.firstElement();

then, I tried for (child in xml.nodes), for (child in xml.children), for (child in xml.elements)

nothing worked.. can you please provide little example?
thanks

HaxeLib upgrade "overflow"

I've just tried to update my version of mloader and the haxelib utility encountered an error stating "overflow". It seems the zip file which is downloaded is corrupt? It's only 2KB.

complete will case when load failed

when I try to load a not exist txt file with the StringLoader,then i wrote switch case Compelete and Fail(e) like your example.but it didn't case the fail,then it case the Complete.both flash and windows
occured that.

Image JS Cross-Origin

Recently changes to ImageLoader added a crossOrigin property to generated ImageElements in JS target HTML (e.g. when used by mui.display.Image).

It's currently on by default and you're able to opt out by adding a compilation flag to your project:

-D default_cross_origin

Many third party image hosts/services don't yet support this and you're forced to add the flag to your project otherwise loading their images are blocked. Additionally if your app is loading images off multiple third party servers it's possible that some may need the crossOrigin property set while others won't.

I propose we change it to be opt-in instead of opt-out, and also set it at the class level instead of globally.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.