Skip to content

Instantly share code, notes, and snippets.

@edwardwbli
Created January 11, 2017 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwardwbli/40a6354c1b5a5fd0fc8b850ae5a2f2be to your computer and use it in GitHub Desktop.
Save edwardwbli/40a6354c1b5a5fd0fc8b850ae5a2f2be to your computer and use it in GitHub Desktop.
example for Jquery to use Gundb
<html>
<body>
<h1>Thoughts</h1>
<form>
<input><button>Add</button>
</form>
<ul></ul>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://rawgit.com/amark/gun/e9e8804de8249f58340e3810721cd5c2a0f78fcd/gun.js"></script>
<script>
var gun = Gun().get('thoughts');
$('form').on('submit', function(event){
event.preventDefault();
gun.set($('input').val());
$('input').val("");
});
gun.on().map(function(thought, id){
var li = $('#' + id).get(0) || $('<li>').attr('id', id).appendTo('ul');
if(thought){
$(li).text(thought);
} else {
$(li).hide();
}
});
$('body').on('dblclick', 'li', function(event){
gun.path(this.id).put(null);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment