blocktalk-custom-widgets
v1.0.2
Published
Create custom widgets for BlockTalk and effortlessly sync data
Downloads
1
Readme
Installation
Simply add the cdn link for the minified js in the <head>
tag of your html
<head>
<script src="https://unpkg.com/blocktalk-custom-widgets"></script>
</head>
Usage
- To get the current data:
BlockTalk.data
// {} - To subscribe to data changes:
BlockTalk.onupdate = (updates) => console.log(updates)
- To update the synced data to all clients:
BlockTalk.UpdatesSelf(yourChanges)
. Keep in mind you only have to push the actual data changes
Simple plain JS Example
This will display a number and add one to it on click. The number is synced across all clients
<html>
<head>
<script src="https://unpkg.com/blocktalk-custom-widgets"></script>
</head>
<body>
<div id="val">0</div>
<button id="inc">+1</button>
<script>
BlockTalk.onupdate = data => document.getElementById("val").innerHTML = data.val || 0
document.getElementById("inc").onclick = function() {
BlockTalk.UpdateSelf({val: ((BlockTalk.data || {}).val || 0) + 1})
}
</script>
</body>
</html>