Last active
April 20, 2016 15:40
-
-
Save leemason/f21d9fd9a267671e31e1d78fcea0cf7f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//The model could be used both server and browser side, | |
//not much more than a plain object with some simple getters and setters. | |
let User = Model.extend({ | |
first_name: String, | |
last_name: String, | |
full_name: function(){ | |
return this.first_name + ' ' + this.last_name; | |
} | |
}); | |
//The repository should be server side only, this handles the db and mapping user updates | |
let UserRepo = Repository.extend({ | |
model: User, | |
table: 'users' | |
//custom queries + extended Repository base methods like findById etc | |
}); | |
//Server side | |
let user = UserRepo.findById(1);//returns an instance of User | |
user.first_name = 'test'; | |
UserRepo.save(user); | |
//Browser side | |
//user passed via inline js into window or something like that on load, not really important. | |
let user = window.user; | |
user.first_name = 'something'; | |
//no way to directly save user here, you will need some rest api for that BY DESIGN!!! | |
ApiService.updateUser(user) | |
.then(function(response){ | |
if(response.status == 200 && response.body.status == 'success'){ | |
//... | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment