I'm working on a project that will grow very fast and I am trying to build it with TDD in mind - that concept that everyone uses, but few of them are actually implementing it. As frontend technologies KnockoutJS and Typescript were the winners and both are almost new to me, but I got the idea behind them.
For the moment I am building up the boilerplate and I am stuck in my freaking and annoying ideas about how to do this properly. Before I've used AngularJS and things were a bit different. And, because I am coming from the magic world of angular framework, I would also like to include some kind of $injector in this project.
So, to stop the story, this is what I have in mind ( notes & explanations below each code section )
Model
module Models
{
export class Person
{
//code for person
}
}
I dont' think I need anything fancy for models. Maybe a BaseModel that should be extend by the rest, but that should be discover while the project is growing.
So, my first question:
Q1: Do you treat your models in a different way, or you see them as simple POCO(POJO) objects ?
ViewModel
module ViewModels
{
export class PersonViewModel extends Editable
{
@inject('PersonRepository')
personService:PersonRepository
// stuff specific for current view model
}
}
As you can see, here are few concepts I would like to use.
First of all that base class for view models Editable, which is used for Editor pattern ( link provided )
Second, @inject decorator is used for DI, to inject repositories in view models ( somehow similar with injecting angular services into controllers, at least the logic, not the implementation )
Third, I added another layer, the Repository layer. I've added this for testing purposes, to separate some concerns that should stay in a service and not in a view model.
Q2: Should I use a
BaseViewModelwhich will implementEditable( this would contain stuff like sorting, filtering, at least, this is what I have in mind right now ). If so, what do you usually do in yourBaseViewModelclass?
Repository
module Repository
{
export class PersonRepository
{
// repo stuff
}
}
Question nr 3:
Q3: Is there any reason to add a
BaseRepositoryin a knockout application ? Did you do/ are you doing something like that ? Because I see no reason to add one.Q4: Should I return a
Promiseor usecallbacksfor server side calls ? I think promises is a more elegant way to do it.Q5: Repositories will be mainly used for server side calls and for performing logic needed for view model. It's ok ?
View
No explanations here
Please note I want DI to decouple some things and make them more testable ( for example I can inject a fake repository in tests ).
Any advice is appreciated. Thank you !
Aucun commentaire:
Enregistrer un commentaire