Skip to content

Commit 370c5bf

Browse files
committed
Mention that items of data should be replaced instead of updated inplace
1 parent eef0280 commit 370c5bf

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

site/js/site.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,12 @@ function onSiteDependenciesLoaded() {
586586
/**
587587
* ### Update
588588
*
589-
* To update a graphic one needs to call `functionPlot` on the same target
590-
* element with *any* object that is configured properly
589+
* To update a graph call `functionPlot` on the same target
590+
* element with *any* object that is configured properly.
591+
*
592+
* If you want to update properties of a datum (of an element of `data`),
593+
* make sure to **recreate the entire object** instead of changing properties
594+
* from it.
591595
*
592596
* @additionalDOM
593597
*
@@ -609,6 +613,7 @@ function onSiteDependenciesLoaded() {
609613
xLine: true,
610614
yLine: true
611615
}
616+
// Replace the entire object instead of changing properties from it!
612617
options.data[0] = {
613618
fn: 'x * x',
614619
derivative: {
@@ -621,9 +626,8 @@ function onSiteDependenciesLoaded() {
621626
// update the function to be y = x
622627
delete options.title
623628
delete options.tip
624-
options.data[0] = {
625-
fn: 'x'
626-
}
629+
// Replace the entire object instead of changing properties from it!
630+
options.data[0] = { fn: 'x' }
627631
}
628632
functionPlot(options)
629633
})

site/partials/examples.html

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,11 @@
401401
a.addLink(b, c)
402402
b.addLink(a, c)
403403
c.addLink(a, b)</code></pre></div></div><div class="col-md-6 center-block demos"><span class="graph" id="linked-a-multiple"></span><span class="graph" id="linked-b-multiple"></span><span class="graph" id="linked-c-multiple"></span></div></div></div></div><div class="example"><div class="container"><div class="row"><div class="col-md-6"><div class="comment"><h3>Update</h3>
404-
<p>To update a graphic one needs to call <code>functionPlot</code> on the same target
405-
element with <em>any</em> object that is configured properly</p></div><div class="code"><pre><code class="javascript">const options = {
404+
<p>To update a graph call <code>functionPlot</code> on the same target
405+
element with <em>any</em> object that is configured properly.</p>
406+
<p>If you want to update properties of a datum (of an element of <code>data</code>),
407+
make sure to <strong>recreate the entire object</strong> instead of changing properties
408+
from it.</p></div><div class="code"><pre><code class="javascript">const options = {
406409
target: '#quadratic-update',
407410
data: [
408411
{
@@ -418,6 +421,7 @@
418421
xLine: true,
419422
yLine: true
420423
}
424+
// Replace the entire object instead of changing properties from it!
421425
options.data[0] = {
422426
fn: 'x * x',
423427
derivative: {
@@ -430,9 +434,8 @@
430434
// update the function to be y = x
431435
delete options.title
432436
delete options.tip
433-
options.data[0] = {
434-
fn: 'x'
435-
}
437+
// Replace the entire object instead of changing properties from it!
438+
options.data[0] = { fn: 'x' }
436439
}
437440
functionPlot(options)
438441
})

0 commit comments

Comments
 (0)