JS Extension API Methods - metasean-toys/cloaked-spice GitHub Wiki

JavaScript API

##.put

  • When given a location, via a peer, .get(), .path(), or .key(), puts the attached primitive or JavaScript object data at that location.

  • Examples:

  • Primitive on peer:

      ```javascript
      var gun = Gun(location.origin + '/gun')
      gun.put({"primitive"})
      ```
    - Assuming `gun` is the peer variable, this places a primitive string directly on the peer's gun instance.
    - CAUTION: Without a key, this primitive can only be accessed with a subsequent `.all()` call.
  • Object on peer:

    ```javascript
    var gun = Gun(location.origin + '/gun')
    gun.get('example/app/data')
       .put({"propertyName":"propertyValue"})
    ```
    - Assuming `gun` is the peer variable, this places a primitive string directly on the peer's gun instance.
    - CAUTION: Without a key, this primitive can only be accessed with a subsequent `.all()` call.

##.get

##.key

##.all

##.val

##.on - (wraps .val - runs repeatedly over time when there is an update notifies; does NOT see changes in sub-nodes; chained with either path(javascript path) or get(key) OPTION ------ default: false - returns entire object on any node field change (wordage of "node field") opt: true - returns only deltas; the property pair of pairs that are changed

##.map - (wraps .val - loops over sub-items until all current sub-items have been returned) OPTION ------- default: false - each node property pair including break-outs of sub-node opt: true - each node property pair with soul of sub-nodes

##.path - (wraps .get)

##.set - inserts/revises/merges a JSON object into an existing gun representation of a parent JSON object; returns the new object (ensures there is a list item, technically wraps .put that then creates the merge object, grabs the soul id off the newly .put object, uses the soul as the path). User adds compound object (i.e. not primitive) but isn’t setting the path, therefore gun will set it.`

##.val - returns a node (was '.get'); should be accessed with .get(present/pointer/key) BUT MAY be accessed with .path(traverse.path.with.js) HOWEVER if accessed with a path, an actual set of raw JSON objects may be returned`

##.on - (parameter: default false returns entire object; true returns diff)`

##.all - (can take a PEER + KEY set ) returns a graph of (soul:node OR key:node) pairs OR list of key:soul pairs (virtual node)

⚠️ **GitHub.com Fallback** ⚠️