1.1.0 • Published 6 years ago

model-o v1.1.0

Weekly downloads
5
License
Unlicense
Repository
github
Last release
6 years ago

model-o

Simple observable model. Fires change events when values are assigned. Get excited!

npm version

npm install --save model-o

View the demo

usage

	var model = new Model_O({
		str: 'hello',
		obj: {
			a: 'a' // NOTE: unwatchable
		},
		subModel: new Model_O({
			a: 'a' // watchable
		}),
		bool: true,
		num: 123.4567,
		arr: [1, 2, 3, 4, 5]
	})

	console.log(model)

	var onChange = function(newval, oldval, key){
		console.log(key, 'newval: ' + newval + ', oldval: ' + oldval)
	}
	model.on('str', onChange)
	model.str = 'asdf'
	model.str += 'asdf'

	model.subModel.on('a', onChange)
	model.subModel.a = 'A'

	model.on('arr', onChange)
	model.arr = model.arr.concat('extra')