Skip to content

Instantly share code, notes, and snippets.

@stryju
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stryju/3eba66f90848f0cb376c to your computer and use it in GitHub Desktop.
Save stryju/3eba66f90848f0cb376c to your computer and use it in GitHub Desktop.
preferred state $http resolution
const state = {
resolve : {
foo : ( $http ) => $http.get( '/foo' )
},
controller : Controller
}
class Controller {
constructor( foo ) {
this.foo = foo.data;
}
}
const state = {
resolve : {
foo : ( $http ) => $http.get( '/foo' ).then( ( response ) => response.data )
},
controller : Controller
}
class Controller {
constructor( foo ) {
this.foo = foo;
}
}
const state = {
resolve : {
foo : ( $q, $http ) => {
const request = $http.get( '/foo' );
return $q( ( resolve, reject ) => request.success( resolve ).error( reject ) )
},
controller : Controller
}
class Controller {
constructor( foo ) {
this.foo = foo;
}
}
const state = {
resolve : {
foo : ( $q, $http ) => {
const deferred = $q.defer();
$http.get( '/foo' ).success( deferred.resolve ).error( deferred.reject );
return deferred.promise;
},
controller : Controller
}
class Controller {
constructor( foo ) {
this.foo = foo;
}
}

state = state Controller = state's controller

@ProLoser
Copy link

04.es6:

const state = {
  resolve : {
    foo : Foo => Foo.list()
  }
}

class Foo {
  static list() {
    return $http.get('/foo').then( response => new Foo(response.data) );
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment