Created
September 18, 2018 06:54
-
-
Save nemtsov/0d7ad9c3678cfb299f3369de82d71ec1 to your computer and use it in GitHub Desktop.
Understanding Gun.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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