1.0.2 • Published 6 years ago

blocktalk-custom-widgets v1.0.2

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

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>
1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago