Cascade

Cascade

TL;DR: For a function named balance() call getBalance() on its parent to execute the function. Otherwise a Cascade (chainable function) structure is returned. Advanced: A Live structure makes use of underlying websocket APIs.

  1. Chaining .get() after .balance(), an HTTP request to get the balance given the provided arguments. Example: .balance(address).get(); Equivalent: .getBalance()address;
  2. Chaning .on(callback) after .balance() provides a Websocket subscription where new data is provided to the 'callback' function as it is received. Example: .balance(address).on(console.log). Equivalent: .onBalance(address,console.log);
  3. Chaining .live() to .balance() returns a pointer to a live variable. When you assign this live variable to one of your object's keys, the object's key is updated with new data automatically as it comes in. Example: user.bal = BCH.balance(address).live(); // user.bal is always updated with latest data. However, if you were to assign this value to a non-object (like var user = xx.live()), it wouldn't work because javascript pointers only work when assigned as a key to existing objects and not newly initialized variables.
  4. Chaining .off() to .balance() should turn off the .balance() object, but only if you've saved the original object returned by the .balance() that you called 'on' on.
  5. The 'transaction' function also includes chains like .build(), .sign(), and .send(). It expects an object for these inputs. Its .get(), .live(), .on() functions expects an object with 'hash' as a key or a string. LibCoin is a wrapper over other cryptocurrency libraries, which frequently have syntax that differs most greatly in relation to websockets and HTTP requests. Our becomes much smaller using Cascade varaibles.