1.3.0 • Published 10 years ago

moldy-ajax-adapter v1.3.0

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

TOC

model-ajax-adapter

Tell the Moldy to use the ajax adapter.

// Moldy.use( require('moldy-ajax-adapter') );

create

should create by a property.

var personMoldy = Moldy.extend( 'person', {
	key: 'hash',
	baseUrl: 'http://localhost:3000/api',
	properties: {
		name: '',
		age: ''
	}
} ).create();
personMoldy.name = 'David';
personMoldy.$save( function ( _error ) {
	personMoldy.name.should.eql( 'David' );
	_done( _error );
} );

findOne

should findOne by a property.

var personMoldy = Moldy.extend( 'person', {
	key: 'guid',
	baseUrl: 'http://localhost:3000/api',
	properties: {
		name: '',
		age: ''
	}
} );
personMoldy.$findOne( {
	guid: '5f55821f-3a28-45c3-b91d-7df927a863d8'
}, function ( _error, _person ) {
	_person.name.should.eql( 'Bennett Sanchez' );
	_done( _error );
} );

find

should find.

var personMoldy = Moldy.extend( 'person', {
	key: 'guid',
	baseUrl: 'http://localhost:3000/api',
	properties: {
		name: '',
		age: ''
	}
} );
personMoldy.$find( function ( _error, _people ) {
	_people.should.be.an.Array;
	_people.should.have.a.lengthOf( 3 );
	_people.forEach( function ( _person ) {
		_person.should.be.a.Moldy;
		_person.should.have.a.property( 'guid' );
		_person.should.have.a.property( 'name' );
		_person.should.have.a.property( 'age' );
		Object.keys( _person.$json() ).should.have.a.lengthOf( 3 );
	} );
	_done( _error );
} );

save

should save a model.

var personMoldy = Moldy.extend( 'person', {
	key: 'guid',
	baseUrl: 'http://localhost:3000/api',
	properties: {
		name: '',
		age: ''
	}
} );
personMoldy.$findOne( {
	guid: '5f55821f-3a28-45c3-b91d-7df927a863d8'
}, function ( _error, _person ) {
	if ( _error ) {
		return _done( _error );
	}
	_person.name = 'Mr Bennett Sanchez';
	_person.$save( _done );
} );

destroy

should destroy a model.

var personMoldy = Moldy.extend( 'person', {
	key: 'guid',
	baseUrl: 'http://localhost:3000/api',
	properties: {
		name: '',
		age: ''
	}
} );
personMoldy.$findOne( {
	guid: '5f55821f-3a28-45c3-b91d-7df927a863d8'
}, function ( _error, _person ) {
	if ( _error ) {
		return _done( _error );
	}
	_person.$destroy( _done );
} );
1.3.0

10 years ago

1.1.4

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago