Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Class Wraps to
ObservableArray<T> Array<T>
ObservableVector<T> Vector<T>

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

About

A set of data structures with events, observable and serializable properties based on pre-existing Haxe data structures.

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages