Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <script src="https://rawgit.com/amark/gun/master/gun.js"></script>
</body>
</html>
 
localStorage.clear();
// Read https://github.com/amark/gun/wiki/Graphs
var gun = Gun();
var alice = gun.get('person/alice').put({name: 'alice', age: 22});
var bob = gun.get('person/bob').put({name: 'bob', age: 24});
var carl = gun.get('person/carl').put({name: 'carl', age: 16});
var dave = gun.get('person/dave').put({name: 'dave', age: 42});
alice.on(function(node){
  //console.log('Subscribed to Alice!', node);
});
gun.get('person/bob').val(function(node){
  //console.log('Bob!', node);
});
var people = gun.get('people');
people.set(alice);
people.set(bob);
people.set(carl);
people.set(dave);
people.map().val(function(person){
  //console.log("The person is", person);
});
var company = gun.get('startup/hype').put({
  name: "hype",
  profitable: false,
  address: {
    street: "123 Hipster Lane",
    city: "San Francisco",
    state: "CA",
    country: "USA"
  }
});
company.val(function(startup){
  //console.log("The startup:", startup);
});
company.get('address').get('city').val(function(value, field){
  //console.log("What is the city?", value);
});
gun.get('startup/hype').put({ // or you could do `company.put({` instead.
  funded: true,
  address: {
    street: "999 Expensive Boulevard"
  }
});
var employees = company.get('employees');
employees.set(dave);
employees.set(alice);
employees.set(bob);
alice.get('spouse').put(bob);
bob.get('spouse').put(alice);
alice.get('spouse').get('employer').put(company);
alice.get('employer').put(company);
dave.get('kids').set(carl);
carl.get('dad').put(dave);
carl.get('friends').set(alice);
carl.get('friends').set(bob);
gun.get('person/alice').get('spouse').get('employer').get('employees').map().get('name').val(function(data, key){
  console.log("The employee's", key, data);
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers