@@ -1250,6 +1250,8 @@ var _default = /*#__PURE__*/function (_Controller) {
1250
1250
} , {
1251
1251
key : "connect" ,
1252
1252
value : function connect ( ) {
1253
+ var _this2 = this ;
1254
+
1253
1255
// hide "loading" elements to begin with
1254
1256
// This is done with CSS, but only for the most basic cases
1255
1257
this . _onLoadingFinish ( ) ;
@@ -1259,6 +1261,14 @@ var _default = /*#__PURE__*/function (_Controller) {
1259
1261
}
1260
1262
1261
1263
window . addEventListener ( 'beforeunload' , this . markAsWindowUnloaded ) ;
1264
+ this . element . addEventListener ( 'live:update-model' , function ( event ) {
1265
+ // ignore events that we dispatched
1266
+ if ( event . target === _this2 . element ) {
1267
+ return ;
1268
+ }
1269
+
1270
+ _this2 . _handleChildComponentUpdateModel ( event ) ;
1271
+ } ) ;
1262
1272
1263
1273
this . _dispatchEvent ( 'live:connect' ) ;
1264
1274
}
@@ -1291,7 +1301,7 @@ var _default = /*#__PURE__*/function (_Controller) {
1291
1301
} , {
1292
1302
key : "action" ,
1293
1303
value : function action ( event ) {
1294
- var _this2 = this ;
1304
+ var _this3 = this ;
1295
1305
1296
1306
// using currentTarget means that the data-action and data-action-name
1297
1307
// must live on the same element: you can't add
@@ -1311,9 +1321,9 @@ var _default = /*#__PURE__*/function (_Controller) {
1311
1321
// then the action Ajax will start. We want to avoid the
1312
1322
// re-render request from starting after the debounce and
1313
1323
// taking precedence
1314
- _this2 . _clearWaitingDebouncedRenders ( ) ;
1324
+ _this3 . _clearWaitingDebouncedRenders ( ) ;
1315
1325
1316
- _this2 . _makeRequest ( directive . action ) ;
1326
+ _this3 . _makeRequest ( directive . action ) ;
1317
1327
} ;
1318
1328
1319
1329
var handled = false ;
@@ -1338,13 +1348,13 @@ var _default = /*#__PURE__*/function (_Controller) {
1338
1348
{
1339
1349
var length = modifier . value ? modifier . value : DEFAULT_DEBOUNCE ; // clear any pending renders
1340
1350
1341
- if ( _this2 . actionDebounceTimeout ) {
1342
- clearTimeout ( _this2 . actionDebounceTimeout ) ;
1343
- _this2 . actionDebounceTimeout = null ;
1351
+ if ( _this3 . actionDebounceTimeout ) {
1352
+ clearTimeout ( _this3 . actionDebounceTimeout ) ;
1353
+ _this3 . actionDebounceTimeout = null ;
1344
1354
}
1345
1355
1346
- _this2 . actionDebounceTimeout = setTimeout ( function ( ) {
1347
- _this2 . actionDebounceTimeout = null ;
1356
+ _this3 . actionDebounceTimeout = setTimeout ( function ( ) {
1357
+ _this3 . actionDebounceTimeout = null ;
1348
1358
1349
1359
_executeAction ( ) ;
1350
1360
} , length ) ;
@@ -1378,14 +1388,14 @@ var _default = /*#__PURE__*/function (_Controller) {
1378
1388
throw new Error ( "The update() method could not be called for \"" . concat ( clonedElement . outerHTML , "\": the element must either have a \"data-model\" or \"name\" attribute set to the model name." ) ) ;
1379
1389
}
1380
1390
1381
- this . $updateModel ( model , value , element , shouldRender ) ;
1391
+ this . $updateModel ( model , value , shouldRender ) ;
1382
1392
}
1383
1393
} , {
1384
1394
key : "$updateModel" ,
1385
- value : function $updateModel ( model , value , element ) {
1386
- var _this3 = this ;
1395
+ value : function $updateModel ( model , value ) {
1396
+ var _this4 = this ;
1387
1397
1388
- var shouldRender = arguments . length > 3 && arguments [ 3 ] !== undefined ? arguments [ 3 ] : true ;
1398
+ var shouldRender = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : true ;
1389
1399
var directives = parseDirectives ( model ) ;
1390
1400
1391
1401
if ( directives . length > 1 ) {
@@ -1414,7 +1424,12 @@ var _default = /*#__PURE__*/function (_Controller) {
1414
1424
1415
1425
if ( ! doesDeepPropertyExist ( this . dataValue , modelName ) ) {
1416
1426
console . warn ( "Model \"" . concat ( modelName , "\" is not a valid data-model value" ) ) ;
1417
- } // we do not send old and new data to the server
1427
+ }
1428
+
1429
+ this . _dispatchEvent ( 'live:update-model' , {
1430
+ model : modelName ,
1431
+ value : value
1432
+ } ) ; // we do not send old and new data to the server
1418
1433
// we merge in the new data now
1419
1434
// TODO: handle edge case for top-level of a model with "exposed" props
1420
1435
// For example, suppose there is a "post" field but "post.title" is exposed.
@@ -1443,16 +1458,16 @@ var _default = /*#__PURE__*/function (_Controller) {
1443
1458
this . _clearWaitingDebouncedRenders ( ) ;
1444
1459
1445
1460
this . renderDebounceTimeout = setTimeout ( function ( ) {
1446
- _this3 . renderDebounceTimeout = null ;
1461
+ _this4 . renderDebounceTimeout = null ;
1447
1462
1448
- _this3 . $render ( ) ;
1463
+ _this4 . $render ( ) ;
1449
1464
} , this . debounceValue || DEFAULT_DEBOUNCE ) ;
1450
1465
}
1451
1466
}
1452
1467
} , {
1453
1468
key : "_makeRequest" ,
1454
1469
value : function _makeRequest ( action ) {
1455
- var _this4 = this ;
1470
+ var _this5 = this ;
1456
1471
1457
1472
var _this$urlValue$split = this . urlValue . split ( '?' ) ,
1458
1473
_this$urlValue$split2 = _slicedToArray ( _this$urlValue$split , 2 ) ,
@@ -1489,15 +1504,15 @@ var _default = /*#__PURE__*/function (_Controller) {
1489
1504
this . renderPromiseStack . addPromise ( thisPromise ) ;
1490
1505
thisPromise . then ( function ( response ) {
1491
1506
// if another re-render is scheduled, do not "run it over"
1492
- if ( _this4 . renderDebounceTimeout ) {
1507
+ if ( _this5 . renderDebounceTimeout ) {
1493
1508
return ;
1494
1509
}
1495
1510
1496
- var isMostRecent = _this4 . renderPromiseStack . removePromise ( thisPromise ) ;
1511
+ var isMostRecent = _this5 . renderPromiseStack . removePromise ( thisPromise ) ;
1497
1512
1498
1513
if ( isMostRecent ) {
1499
1514
response . json ( ) . then ( function ( data ) {
1500
- _this4 . _processRerender ( data ) ;
1515
+ _this5 . _processRerender ( data ) ;
1501
1516
} ) ;
1502
1517
}
1503
1518
} ) ;
@@ -1566,21 +1581,21 @@ var _default = /*#__PURE__*/function (_Controller) {
1566
1581
} , {
1567
1582
key : "_handleLoadingToggle" ,
1568
1583
value : function _handleLoadingToggle ( isLoading ) {
1569
- var _this5 = this ;
1584
+ var _this6 = this ;
1570
1585
1571
1586
this . _getLoadingDirectives ( ) . forEach ( function ( _ref ) {
1572
1587
var element = _ref . element ,
1573
1588
directives = _ref . directives ;
1574
1589
1575
1590
// so we can track, at any point, if an element is in a "loading" state
1576
1591
if ( isLoading ) {
1577
- _this5 . _addAttributes ( element , [ 'data-live-is-loading' ] ) ;
1592
+ _this6 . _addAttributes ( element , [ 'data-live-is-loading' ] ) ;
1578
1593
} else {
1579
- _this5 . _removeAttributes ( element , [ 'data-live-is-loading' ] ) ;
1594
+ _this6 . _removeAttributes ( element , [ 'data-live-is-loading' ] ) ;
1580
1595
}
1581
1596
1582
1597
directives . forEach ( function ( directive ) {
1583
- _this5 . _handleLoadingDirective ( element , isLoading , directive ) ;
1598
+ _this6 . _handleLoadingDirective ( element , isLoading , directive ) ;
1584
1599
} ) ;
1585
1600
} ) ;
1586
1601
}
@@ -1594,50 +1609,50 @@ var _default = /*#__PURE__*/function (_Controller) {
1594
1609
} , {
1595
1610
key : "_handleLoadingDirective" ,
1596
1611
value : function _handleLoadingDirective ( element , isLoading , directive ) {
1597
- var _this6 = this ;
1612
+ var _this7 = this ;
1598
1613
1599
1614
var finalAction = parseLoadingAction ( directive . action , isLoading ) ;
1600
1615
var loadingDirective = null ;
1601
1616
1602
1617
switch ( finalAction ) {
1603
1618
case 'show' :
1604
1619
loadingDirective = function loadingDirective ( ) {
1605
- _this6 . _showElement ( element ) ;
1620
+ _this7 . _showElement ( element ) ;
1606
1621
} ;
1607
1622
1608
1623
break ;
1609
1624
1610
1625
case 'hide' :
1611
1626
loadingDirective = function loadingDirective ( ) {
1612
- return _this6 . _hideElement ( element ) ;
1627
+ return _this7 . _hideElement ( element ) ;
1613
1628
} ;
1614
1629
1615
1630
break ;
1616
1631
1617
1632
case 'addClass' :
1618
1633
loadingDirective = function loadingDirective ( ) {
1619
- return _this6 . _addClass ( element , directive . args ) ;
1634
+ return _this7 . _addClass ( element , directive . args ) ;
1620
1635
} ;
1621
1636
1622
1637
break ;
1623
1638
1624
1639
case 'removeClass' :
1625
1640
loadingDirective = function loadingDirective ( ) {
1626
- return _this6 . _removeClass ( element , directive . args ) ;
1641
+ return _this7 . _removeClass ( element , directive . args ) ;
1627
1642
} ;
1628
1643
1629
1644
break ;
1630
1645
1631
1646
case 'addAttribute' :
1632
1647
loadingDirective = function loadingDirective ( ) {
1633
- return _this6 . _addAttributes ( element , directive . args ) ;
1648
+ return _this7 . _addAttributes ( element , directive . args ) ;
1634
1649
} ;
1635
1650
1636
1651
break ;
1637
1652
1638
1653
case 'removeAttribute' :
1639
1654
loadingDirective = function loadingDirective ( ) {
1640
- return _this6 . _removeAttributes ( element , directive . args ) ;
1655
+ return _this7 . _removeAttributes ( element , directive . args ) ;
1641
1656
} ;
1642
1657
1643
1658
break ;
@@ -1741,7 +1756,7 @@ var _default = /*#__PURE__*/function (_Controller) {
1741
1756
} , {
1742
1757
key : "_executeMorphdom" ,
1743
1758
value : function _executeMorphdom ( newHtml ) {
1744
- var _this7 = this ;
1759
+ var _this8 = this ;
1745
1760
1746
1761
// https://stackoverflow.com/questions/494143/creating-a-new-dom-element-from-an-html-string-using-built-in-dom-methods-or-pro#answer-35385518
1747
1762
function htmlToElement ( html ) {
@@ -1760,7 +1775,7 @@ var _default = /*#__PURE__*/function (_Controller) {
1760
1775
} // avoid updating child components: they will handle themselves
1761
1776
1762
1777
1763
- if ( fromEl . hasAttribute ( 'data-controller' ) && fromEl . getAttribute ( 'data-controller' ) . split ( ' ' ) . indexOf ( 'live' ) !== - 1 && fromEl !== _this7 . element ) {
1778
+ if ( fromEl . hasAttribute ( 'data-controller' ) && fromEl . getAttribute ( 'data-controller' ) . split ( ' ' ) . indexOf ( 'live' ) !== - 1 && fromEl !== _this8 . element ) {
1764
1779
return false ;
1765
1780
}
1766
1781
@@ -1771,7 +1786,7 @@ var _default = /*#__PURE__*/function (_Controller) {
1771
1786
} , {
1772
1787
key : "_initiatePolling" ,
1773
1788
value : function _initiatePolling ( rawPollConfig ) {
1774
- var _this8 = this ;
1789
+ var _this9 = this ;
1775
1790
1776
1791
var directives = parseDirectives ( rawPollConfig || '$render' ) ;
1777
1792
directives . forEach ( function ( directive ) {
@@ -1790,23 +1805,23 @@ var _default = /*#__PURE__*/function (_Controller) {
1790
1805
}
1791
1806
} ) ;
1792
1807
1793
- _this8 . startPoll ( directive . action , duration ) ;
1808
+ _this9 . _startPoll ( directive . action , duration ) ;
1794
1809
} ) ;
1795
1810
}
1796
1811
} , {
1797
- key : "startPoll " ,
1798
- value : function startPoll ( actionName , duration ) {
1799
- var _this9 = this ;
1812
+ key : "_startPoll " ,
1813
+ value : function _startPoll ( actionName , duration ) {
1814
+ var _this10 = this ;
1800
1815
1801
1816
var callback ;
1802
1817
1803
1818
if ( actionName . charAt ( 0 ) === '$' ) {
1804
1819
callback = function callback ( ) {
1805
- _this9 [ actionName ] ( ) ;
1820
+ _this10 [ actionName ] ( ) ;
1806
1821
} ;
1807
1822
} else {
1808
1823
callback = function callback ( ) {
1809
- _this9 . _makeRequest ( actionName ) ;
1824
+ _this10 . _makeRequest ( actionName ) ;
1810
1825
} ;
1811
1826
}
1812
1827
@@ -1827,6 +1842,15 @@ var _default = /*#__PURE__*/function (_Controller) {
1827
1842
} ) ;
1828
1843
return this . element . dispatchEvent ( userEvent ) ;
1829
1844
}
1845
+ } , {
1846
+ key : "_handleChildComponentUpdateModel" ,
1847
+ value : function _handleChildComponentUpdateModel ( event ) {
1848
+ if ( ! doesDeepPropertyExist ( this . dataValue , event . detail . model ) ) {
1849
+ return ;
1850
+ }
1851
+
1852
+ this . $updateModel ( event . detail . model , event . detail . value , false ) ;
1853
+ }
1830
1854
} ] ) ;
1831
1855
1832
1856
return _default ;
0 commit comments