shock01 / oig

Playing around with ES6, MVVM and stuff like that
1 stars 1 forks source link

Assignviewmodel to view should use dicontext #38

Open shock01 opened 8 years ago

shock01 commented 8 years ago

Instead of method assignviewmodel to view pass provider argument to dicontextconstructor

So view should be injected to viewmodel and visa versa. Current implementation will throw circular dependency so that should be fixed by passing provider argument

Example: dicontext.resolve(viewmodel, {view: binding}. Where dicontext will call diconstructor and passing a provider for the current instance

This will actually solve circular dependencies in general so unit test needs to change to not throw circular dependency. Actually test should be removed

Oig view attribute will not be needed for di, only for view resolving in eg event handlers.

The element to which the viewcontext is bound should also be passed to dicontext.resolve as provider named element. That way the view dom element can also be injected

Pls use feature branch and pull requests

Circular dependencies in constructor injection is actual an anti pattern http://misko.hevery.com/2008/08/01/circular-dependency-in-constructors-and-dependency-injection/

We might need to rethink the solution maybe view needs a setter method for viewmodel or visa versa Also viewmodel locator pattern is use in. Net

Lets discuss

shock01 commented 8 years ago

More...

$viewModel will not be needed anymore because viewModel can be resolved by view.

eg

.bind('viewModel', function (){ return { alert: functon () { }} });

.bind('blaat').to(function (viewModel) { this.viewModel = viewModel return this; })

shock01 commented 8 years ago

https://github.com/google/guice/wiki/CyclicDependencies