GithubHelp home page GithubHelp logo

dartbeans's Introduction

Bitdeli Badge

DartBeans

A Dart library that helps working with beans and event streams.

To know something more about the released version have a look at the CHANGELOG.

Getting started

1. Add the following dependency to your pubspec.yaml and run pub get:

dependencies:
	dartbeans: any

2. Add dartbeans to your code and run it:

import "package:dartbeans/dartbeans.dart";

void main() {
	DartBean person = new DartBean();

	person.onPropertyChangedEvents["name"]
		.listen((PropertyChangedEvent event) =>
			print("Changed: ${event.property} = ${event.newValue}"));

	person["name"] = "Hans";
}

Beans

The common way to use DartBeans is by extending the DartBean class and by adding extra code for accessing properties:

class Person extends DartBean {
	static const NAME = "name";
	static const AGE = "age";

	String get name => this[NAME];

	void set name(String name) {
		this[NAME] = name;
	}

	int get age => this[AGE];

	void set age(int age) {
		this[AGE] = age;
	}
}

Property changed event streams are exposed by the onPropertyChangedEvents getter on the DartBean class and can be accessed in a convenient way:

	Stream<PropertyChangedEvent> get onNameChanged =>
		onPropertyChangedEvents[NAME];
	Stream<PropertyChangedEvent> get onAgeChanged =>
		onPropertyChangedEvents[AGE];

Custom events can be easily implemented:

	static const REFRESHED_EVENT_TYPE = "refreshed";

	Stream<FLEvent> get onRefreshed => onEvents[REFRESHED_EVENT_TYPE];

	void refresh() {
		dispatch(REFRESHED_EVENT_TYPE); // dispatch an FLEvent
	}

Then working with our beans is very simple:

void main() {
	Person person = new Person();

	// listen to changes on name property
	person.onNameChanged.listen((PropertyChangedEvent event) {
		print("1. Property change ${event.property} = ${event.newValue}"
			+ " on ${event.target}");
	});

	// listen to changes on age property
	person.onAgeChanged.listen((PropertyChangedEvent event) {
		print("2. Property change ${event.property} = ${event.newValue}"
			+ " on ${event.target}");
	});

	// listen to refreshes
	person.onRefreshed.listen((FLEvent event) {
		print("3. Refresh on ${event.target}");
	});

	person.name = "Hans";
	person.age = 18;
	person.refresh();
}

Binders

TODOC

Bean chainings

TODOC

Under the covers

TODOC

###Event providers###

TODOC

###Discriminated events###

TODOC

###Event bubbling###

TODOC

Examples

Examples that show the use of DartBeans are in the example folder.

Running Tests

To run the tests just run the test/dartbeans_test.dart file.

Any Comments?

You're welcome! Just visit the GitHub page and open a new issue or mail me.

dartbeans's People

Contributors

fromlabs avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

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.