Skip to content

Instantly share code, notes, and snippets.

@nemtsov
Created September 18, 2018 06:54
Show Gist options
  • Save nemtsov/0d7ad9c3678cfb299f3369de82d71ec1 to your computer and use it in GitHub Desktop.
Save nemtsov/0d7ad9c3678cfb299f3369de82d71ec1 to your computer and use it in GitHub Desktop.
Understanding Gun.js
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Understand Gun</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
#app {
padding: 50px;
}
#app * {
font-family: 'Helvetica Neue';
font-size: 110%;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<form @submit.prevent="submit">
<input v-model="name" placeholder="name" />
<button>submit</button>
</form>
</div>
<script src="main.js"></script>
</body>
</html>
const gun = Gun(['http://localhost:8080/gun']);
var app = new Vue({
el: '#app',
data: {
name: ''
},
mounted() {
this.helloNode = gun.get('hello');
this.helloNode.on((data, key) => {
this.name = data.name;
});
},
methods: {
submit() {
this.helloNode.put({ name: this.name });
}
}
});
const Gun = require('gun');
const { createServer } = require('http');
const web = createServer(Gun.serve(`${__dirname}/public`)).listen(8080);
const gun = Gun({ web });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment