Skip to content

Instantly share code, notes, and snippets.

@nchanged
Created July 26, 2016 10:05
Show Gist options
  • Save nchanged/b0abb7849fdb8417fc1712d9ca0b5c23 to your computer and use it in GitHub Desktop.
Save nchanged/b0abb7849fdb8417fc1712d9ca0b5c23 to your computer and use it in GitHub Desktop.
class MyChain {
setFoo() {
// I am the first one. And i set this.foo = "foo1"
return "foo1";
}
setBar() {
// I am the second one, and i have "this.foo" at my disposal
// And i set this.bar = "bar1"
return "bar1";
}
justSomethingFunky()
{
// I am the third one, and everyone will wait for me
let self = this;
return new Promise(function(resolve, reject){
// But i will not assign anything
// Just have to resolve myself
return resolve(self.bar)
})
}
setHello()
{
// I am the last to be executed, and i will assign this.hello = "world"
return "world";
}
}
realm.chain(MyChain).then(function(result){
// {foo : "foo1", bar : "bar1", hello: "world" }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment