Skip to content

Instantly share code, notes, and snippets.

@stryju

stryju/01.es6

Last active Aug 29, 2015
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@ProLoser ProLoser commented Jun 23, 2015

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