Execute
Save
Share
Share link
share
share
share
Team
Public Teams
Comments
0
Created By:
Guest
Title:
Title
Description
Edit
Copy Link
Login
Email *
Password *
Login
OR
Create Account
Screen Name *
Email *
Password *
Retype Password *
Team Access Code
Register
Public CodeBins
HELP
--Select Theme--
Ambiance
Blackboard
Cobalt
Eclipse
Elegant
Erlang-Dark
Lesser-Dark
Monokai
Neat
Night
Rubyblue
Vibrant-Ink
Xq-Dark
New CodeBin
CodeBins Versions
02/01/2013- V.6
02/01/2013- V.5
02/01/2013- V.4
01/31/2013- V.3
01/31/2013- V.2
01/31/2013- V.1
Compare Versions
Recent CodeBins
View All CodeBins
require(['dojo/topic', 'dojo/query', 'dojo/Stateful', 'dojo/_base/declare'], function(topic, query, Stateful, declare) { var Controller = declare([Stateful], { accounts: { account1: { change: null, value: null }, account2: { change: null, value: null } }, otherData: { foo: null, bar: null } }); var c = new Controller; // the controller will publish a data refresh event as soon as it // receives an update c.watch('accounts', function(prop, oldValue, newValue) { console.log(prop, 'prop changed. Publishing data/refresh...'); topic.publish('data/accounts/refresh', newValue); }); // client modules interested in particular data will subscribe topic.subscribe('data/accounts/refresh', function(data) { var accountValue = data.account1.value; query('.account-value').forEach(function(element) { element.innerHTML = '$' + accountValue; }); }); // a hook to inform the controller that data has changed topic.subscribe('controller/accounts/update', function(data) { console.log('controller/accounts/update', data); c.set('accounts', data); }); query('#update-controller').on('click', function() { topic.publish('controller/accounts/update', getRandomData()); }); // we are not currently planning to update the controller // from inline data, but this is a possibility. on the other hand, // we think it would be a good idea to put the initial data // for a module inside a script tag instead of in data-dojo-props query('#load-inline-data').on('click', function() { var json = query('#bap .data-store')[0].innerHTML; var data = eval('(' + json + ')'); topic.publish('controller/accounts/update', data.accounts); }); }); function getRandomData() { // simulates the data we will receive from the server on a fixed interval return { account1: { change: Math.floor(Math.random() * 1000000), value: Math.floor(Math.random() * 10000) }, account2: { change: Math.floor(Math.random() * 1000000), value: Math.floor(Math.random() * 10000) } }; }
Bottom of Page
In Head
On Load
On Ready
Setting
Validate
Copy
Format
.module { border: 1px solid #333; width: 200px; height: 200px; float: left; margin: 10px; }
Setting
Validate
Copy
Format
<div id="sbm" class="module"> Account 1 Value: <span class="account-value">$734200</span> </div> <div id="bap" class="module"> Account 1 Value: <span class="account-value">$734200</span> <script type="application/json" class="data-store"> { "accounts": { "account1": { "change": 2000, "value": 999999 }, "account2": { "change": 2422, "value": 202393 } } } </script> </div> <p> <button id="update-controller">Update Controller</button> <small>(will happen both at <strong>page load</strong> and on a <strong>fixed interval</strong>)</small> </p> <p> <button id="load-inline-data">Load Inline Data</button> </p>
No Doc Type
HTML5
HTML 4.01 Transitional
HTML 4.01 Strict
HTML 4.01 Frameset
XHTML 1.1
XHTML 1.0 Transitional
XHTML 1.0 Strict
XHTML 1.0 Frameset
Copy
Format
Download
×
Code Description
×
Difference of Versions
HTML
CSS
JS
×
JS Error
×
CSS Error
Errors
Warnings
×
JavaScript Setting
JS Libraries:
Chrome Frame 1.0.3
Dojo 1.8.0
Dojo 1.7.3
Dojo 1.7.2
Ext Core 3.1.0
jQuery 1.8.0
jQuery 1.7.2
jQuery 1.6.0
jQuery 1.5.0
jQuery 1.4.4
jQuery 1.4.0
jQuery-min 1.7.2
jQueryUI-min 1.8.21
MooTools more-1.4.0.1-full
MooTools core-1.4.5-full
MooTools core-1.4.1-full
Prototype 1.7.1.0
script.aculo.us 1.9.0
SWFObject 2.2
Twitter Bootstrap 2.0.4
WebFont Loader 1.0.28
yui 3.5.1
User Libraries:
Upload File
JavaScript URL(s):
×
CSS Setting
CSS Libraries:
jQueryUI 1.8.21
Twitter Bootstrap 2.0.4
User Libraries:
Upload File
CSS URL(s):