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

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.