tracker.ds

A set of data structures with events, observable and serializable properties based on pre-existing Haxe data structures.
https://github.com/Davvex87/tracker.ds

To install, run:

haxelib install tracker.ds 1.0.1 

See using Haxelib in Haxelib documentation for more information.

README.md

Tracker.DS

Paired together with jeremyfa/tracker, tracker.ds provides data structures with events, observable and serializable properties based on pre-existing Haxe data structures, meant to be used inside your data models. It attempts to work around a limitation with the original tracker library where detecting changes to arrays, maps, vectors, etc... can be quite challenging due to the way the library works, as the change events would only trigger if the variable value were changed entierly.

Data structures

ClassWraps to
ObservableArray\Array\
ObservableVector\Vector\

All of these classes can be found under the tracker.ds package.

Example

class Person extends Model
{
	@observe public var name:String;
	@observe public var age:Int;
	
	public var nicknames:ObservableArray<String>;

	public function new(name:String, age:Int)
	{
		super();

		this.name = name;
		this.age = age;
		this.nicknames = new ObservableArray();
	}
}
var testPerson = new Person("Dave", 25);
testPerson.onNameChange(this, (current, previous) -> {
	trace("Name changed from " + previous + " to " + current);
});
testPerson.onAgeChange(this, (current, previous) -> {
	trace("Age changed from " + previous + " to " + current);
});

testPerson.name = "John";
testPerson.age = 30;

testPerson.nicknames.onChanged(this, () -> {
	trace("Nicknames changed!");
});
testPerson.nicknames.onItemInserted(this, (index, item) -> {
	trace("Nickname added at " + index + ": " + item);
});
testPerson.nicknames.onItemRemoved(this, (index, item) -> {
	trace("Nickname removed at " + index + ": " + item);
});

testPerson.nicknames.push("Johnny");
testPerson.nicknames.push("JP");
testPerson.nicknames.push("Davy");
testPerson.nicknames.remove("JP");

trace('nicknames.length = ${testPerson.nicknames.length}'); // 2
trace('nicknames[1] = ${testPerson.nicknames[1]}'); // Davy

Output:

Name changed from Dave to John
Age changed from 25 to 30
Nickname added at 0: Johnny
Nicknames changed!
Nickname added at 1: JP
Nicknames changed!
Nickname added at 2: Davy
Nicknames changed!
Nickname removed at 1: JP
Nicknames changed!
nicknames.length = 2
nicknames[1] = Davy
Contributors
Davvex87
Version
1.0.1
Published
3 months ago
Dependencies
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub

⌂