@eui/core 18.0.0-rc.31 → 18.0.0-rc.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/dependencies.html +1 -1
- package/docs/injectables/LocalStorageService.html +12 -1
- package/docs/injectables/StoreService.html +12 -1
- package/docs/js/search/search_index.js +2 -2
- package/docs/miscellaneous/functions.html +284 -0
- package/docs/miscellaneous/variables.html +58 -21
- package/esm2022/lib/services/storage/local-storage.service.mjs +36 -25
- package/esm2022/lib/services/store/reducers/meta.reducers.mjs +46 -32
- package/esm2022/lib/services/store/store.service.mjs +17 -9
- package/esm2022/lib/services/store/store.service.mock.mjs +3 -2
- package/fesm2022/eui-core.mjs +95 -65
- package/fesm2022/eui-core.mjs.map +1 -1
- package/lib/services/storage/local-storage.service.d.ts +3 -2
- package/lib/services/storage/local-storage.service.d.ts.map +1 -1
- package/lib/services/store/reducers/meta.reducers.d.ts +11 -1
- package/lib/services/store/reducers/meta.reducers.d.ts.map +1 -1
- package/lib/services/store/store.service.d.ts +3 -2
- package/lib/services/store/store.service.d.ts.map +1 -1
- package/lib/services/store/store.service.mock.d.ts +1 -0
- package/lib/services/store/store.service.mock.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -158,6 +158,12 @@
|
|
|
158
158
|
<li>
|
|
159
159
|
<a href="#localStorageSync" title="packages/eui/packages/core/src/lib/services/store/reducers/meta.reducers.ts" ><b>localStorageSync</b> (packages/.../meta.reducers.ts)</a>
|
|
160
160
|
</li>
|
|
161
|
+
<li>
|
|
162
|
+
<a href="#localStorageSync" title="packages/eui/packages/core/src/lib/services/store/reducers/meta.reducers.ts" ><b>localStorageSync</b> (packages/.../meta.reducers.ts)</a>
|
|
163
|
+
</li>
|
|
164
|
+
<li>
|
|
165
|
+
<a href="#localStorageSync" title="packages/eui/packages/core/src/lib/services/store/reducers/meta.reducers.ts" ><b>localStorageSync</b> (packages/.../meta.reducers.ts)</a>
|
|
166
|
+
</li>
|
|
161
167
|
<li>
|
|
162
168
|
<a href="#LogHttpErrorCallbackFn" title="packages/eui/packages/core/src/lib/services/errors/http-error-handler-callback-functions.ts" ><b>LogHttpErrorCallbackFn</b> (packages/.../http-error-handler-callback-functions.ts)</a>
|
|
163
169
|
</li>
|
|
@@ -179,6 +185,12 @@
|
|
|
179
185
|
<li>
|
|
180
186
|
<a href="#sessionStorageSync" title="packages/eui/packages/core/src/lib/services/store/reducers/meta.reducers.ts" ><b>sessionStorageSync</b> (packages/.../meta.reducers.ts)</a>
|
|
181
187
|
</li>
|
|
188
|
+
<li>
|
|
189
|
+
<a href="#sessionStorageSync" title="packages/eui/packages/core/src/lib/services/store/reducers/meta.reducers.ts" ><b>sessionStorageSync</b> (packages/.../meta.reducers.ts)</a>
|
|
190
|
+
</li>
|
|
191
|
+
<li>
|
|
192
|
+
<a href="#sessionStorageSync" title="packages/eui/packages/core/src/lib/services/store/reducers/meta.reducers.ts" ><b>sessionStorageSync</b> (packages/.../meta.reducers.ts)</a>
|
|
193
|
+
</li>
|
|
182
194
|
</ul>
|
|
183
195
|
</td>
|
|
184
196
|
</tr>
|
|
@@ -1658,6 +1670,70 @@ It needs to be added in your application main.ts file.</p>
|
|
|
1658
1670
|
</tr>
|
|
1659
1671
|
<tr>
|
|
1660
1672
|
<td class="col-md-4">
|
|
1673
|
+
<code>localStorageSync(platformId)</code>
|
|
1674
|
+
</td>
|
|
1675
|
+
</tr>
|
|
1676
|
+
|
|
1677
|
+
|
|
1678
|
+
|
|
1679
|
+
|
|
1680
|
+
<tr>
|
|
1681
|
+
<td class="col-md-4">
|
|
1682
|
+
<div class="io-description"><p>Utility meta-reducer to load the state from the local storage</p>
|
|
1683
|
+
</div>
|
|
1684
|
+
|
|
1685
|
+
<div class="io-description">
|
|
1686
|
+
<b>Parameters :</b>
|
|
1687
|
+
|
|
1688
|
+
<table class="params">
|
|
1689
|
+
<thead>
|
|
1690
|
+
<tr>
|
|
1691
|
+
<td>Name</td>
|
|
1692
|
+
<td>Optional</td>
|
|
1693
|
+
<td>Description</td>
|
|
1694
|
+
</tr>
|
|
1695
|
+
</thead>
|
|
1696
|
+
<tbody>
|
|
1697
|
+
<tr>
|
|
1698
|
+
<td>platformId</td>
|
|
1699
|
+
|
|
1700
|
+
<td>
|
|
1701
|
+
No
|
|
1702
|
+
</td>
|
|
1703
|
+
|
|
1704
|
+
|
|
1705
|
+
<td>
|
|
1706
|
+
<p>the platformId based on PLATFORM_ID token of Angular</p>
|
|
1707
|
+
|
|
1708
|
+
</td>
|
|
1709
|
+
</tr>
|
|
1710
|
+
</tbody>
|
|
1711
|
+
</table>
|
|
1712
|
+
</div>
|
|
1713
|
+
<div class="io-description">
|
|
1714
|
+
<b>Returns : </b> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/function" target="_blank" >function</a></code>
|
|
1715
|
+
|
|
1716
|
+
</div>
|
|
1717
|
+
<div class="io-description">
|
|
1718
|
+
|
|
1719
|
+
</div>
|
|
1720
|
+
</td>
|
|
1721
|
+
</tr>
|
|
1722
|
+
</tbody>
|
|
1723
|
+
</table>
|
|
1724
|
+
<table class="table table-sm table-bordered">
|
|
1725
|
+
<tbody>
|
|
1726
|
+
<tr>
|
|
1727
|
+
<td class="col-md-4">
|
|
1728
|
+
<a name="localStorageSync"></a>
|
|
1729
|
+
<span class="name">
|
|
1730
|
+
<span ><b>localStorageSync</b></span>
|
|
1731
|
+
<a href="#localStorageSync"><span class="icon ion-ios-link"></span></a>
|
|
1732
|
+
</span>
|
|
1733
|
+
</td>
|
|
1734
|
+
</tr>
|
|
1735
|
+
<tr>
|
|
1736
|
+
<td class="col-md-4">
|
|
1661
1737
|
<code>localStorageSync(reducer: ActionReducer)</code>
|
|
1662
1738
|
</td>
|
|
1663
1739
|
</tr>
|
|
@@ -1713,6 +1789,142 @@ It needs to be added in your application main.ts file.</p>
|
|
|
1713
1789
|
</tr>
|
|
1714
1790
|
</tbody>
|
|
1715
1791
|
</table>
|
|
1792
|
+
<table class="table table-sm table-bordered">
|
|
1793
|
+
<tbody>
|
|
1794
|
+
<tr>
|
|
1795
|
+
<td class="col-md-4">
|
|
1796
|
+
<a name="localStorageSync"></a>
|
|
1797
|
+
<span class="name">
|
|
1798
|
+
<span ><b>localStorageSync</b></span>
|
|
1799
|
+
<a href="#localStorageSync"><span class="icon ion-ios-link"></span></a>
|
|
1800
|
+
</span>
|
|
1801
|
+
</td>
|
|
1802
|
+
</tr>
|
|
1803
|
+
<tr>
|
|
1804
|
+
<td class="col-md-4">
|
|
1805
|
+
<code>localStorageSync(reducer: ActionReducer, platformId?)</code>
|
|
1806
|
+
</td>
|
|
1807
|
+
</tr>
|
|
1808
|
+
|
|
1809
|
+
|
|
1810
|
+
|
|
1811
|
+
|
|
1812
|
+
<tr>
|
|
1813
|
+
<td class="col-md-4">
|
|
1814
|
+
|
|
1815
|
+
<div class="io-description">
|
|
1816
|
+
<b>Parameters :</b>
|
|
1817
|
+
|
|
1818
|
+
<table class="params">
|
|
1819
|
+
<thead>
|
|
1820
|
+
<tr>
|
|
1821
|
+
<td>Name</td>
|
|
1822
|
+
<td>Type</td>
|
|
1823
|
+
<td>Optional</td>
|
|
1824
|
+
</tr>
|
|
1825
|
+
</thead>
|
|
1826
|
+
<tbody>
|
|
1827
|
+
<tr>
|
|
1828
|
+
<td>reducer</td>
|
|
1829
|
+
<td>
|
|
1830
|
+
<code>ActionReducer</code>
|
|
1831
|
+
</td>
|
|
1832
|
+
|
|
1833
|
+
<td>
|
|
1834
|
+
No
|
|
1835
|
+
</td>
|
|
1836
|
+
|
|
1837
|
+
|
|
1838
|
+
</tr>
|
|
1839
|
+
<tr>
|
|
1840
|
+
<td>platformId</td>
|
|
1841
|
+
<td>
|
|
1842
|
+
</td>
|
|
1843
|
+
|
|
1844
|
+
<td>
|
|
1845
|
+
Yes
|
|
1846
|
+
</td>
|
|
1847
|
+
|
|
1848
|
+
|
|
1849
|
+
</tr>
|
|
1850
|
+
</tbody>
|
|
1851
|
+
</table>
|
|
1852
|
+
</div>
|
|
1853
|
+
<div class="io-description">
|
|
1854
|
+
<b>Returns : </b> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" target="_blank" >Function</a></code>
|
|
1855
|
+
|
|
1856
|
+
</div>
|
|
1857
|
+
<div class="io-description">
|
|
1858
|
+
|
|
1859
|
+
</div>
|
|
1860
|
+
</td>
|
|
1861
|
+
</tr>
|
|
1862
|
+
</tbody>
|
|
1863
|
+
</table>
|
|
1864
|
+
<table class="table table-sm table-bordered">
|
|
1865
|
+
<tbody>
|
|
1866
|
+
<tr>
|
|
1867
|
+
<td class="col-md-4">
|
|
1868
|
+
<a name="sessionStorageSync"></a>
|
|
1869
|
+
<span class="name">
|
|
1870
|
+
<span ><b>sessionStorageSync</b></span>
|
|
1871
|
+
<a href="#sessionStorageSync"><span class="icon ion-ios-link"></span></a>
|
|
1872
|
+
</span>
|
|
1873
|
+
</td>
|
|
1874
|
+
</tr>
|
|
1875
|
+
<tr>
|
|
1876
|
+
<td class="col-md-4">
|
|
1877
|
+
<code>sessionStorageSync(platformId)</code>
|
|
1878
|
+
</td>
|
|
1879
|
+
</tr>
|
|
1880
|
+
|
|
1881
|
+
|
|
1882
|
+
|
|
1883
|
+
|
|
1884
|
+
<tr>
|
|
1885
|
+
<td class="col-md-4">
|
|
1886
|
+
<div class="io-description"><p>Utility meta-reducer to load the state from the session storage</p>
|
|
1887
|
+
</div>
|
|
1888
|
+
|
|
1889
|
+
<div class="io-description">
|
|
1890
|
+
<b>Parameters :</b>
|
|
1891
|
+
|
|
1892
|
+
<table class="params">
|
|
1893
|
+
<thead>
|
|
1894
|
+
<tr>
|
|
1895
|
+
<td>Name</td>
|
|
1896
|
+
<td>Optional</td>
|
|
1897
|
+
<td>Description</td>
|
|
1898
|
+
</tr>
|
|
1899
|
+
</thead>
|
|
1900
|
+
<tbody>
|
|
1901
|
+
<tr>
|
|
1902
|
+
<td>platformId</td>
|
|
1903
|
+
|
|
1904
|
+
<td>
|
|
1905
|
+
No
|
|
1906
|
+
</td>
|
|
1907
|
+
|
|
1908
|
+
|
|
1909
|
+
<td>
|
|
1910
|
+
<p>the platformId based on PLATFORM_ID token of Angular</p>
|
|
1911
|
+
|
|
1912
|
+
</td>
|
|
1913
|
+
</tr>
|
|
1914
|
+
</tbody>
|
|
1915
|
+
</table>
|
|
1916
|
+
</div>
|
|
1917
|
+
<div class="io-description">
|
|
1918
|
+
<b>Returns : </b> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/function" target="_blank" >function</a></code>
|
|
1919
|
+
|
|
1920
|
+
</div>
|
|
1921
|
+
<div class="io-description">
|
|
1922
|
+
|
|
1923
|
+
</div>
|
|
1924
|
+
</td>
|
|
1925
|
+
</tr>
|
|
1926
|
+
</tbody>
|
|
1927
|
+
</table>
|
|
1716
1928
|
<table class="table table-sm table-bordered">
|
|
1717
1929
|
<tbody>
|
|
1718
1930
|
<tr>
|
|
@@ -1781,6 +1993,78 @@ It needs to be added in your application main.ts file.</p>
|
|
|
1781
1993
|
</tr>
|
|
1782
1994
|
</tbody>
|
|
1783
1995
|
</table>
|
|
1996
|
+
<table class="table table-sm table-bordered">
|
|
1997
|
+
<tbody>
|
|
1998
|
+
<tr>
|
|
1999
|
+
<td class="col-md-4">
|
|
2000
|
+
<a name="sessionStorageSync"></a>
|
|
2001
|
+
<span class="name">
|
|
2002
|
+
<span ><b>sessionStorageSync</b></span>
|
|
2003
|
+
<a href="#sessionStorageSync"><span class="icon ion-ios-link"></span></a>
|
|
2004
|
+
</span>
|
|
2005
|
+
</td>
|
|
2006
|
+
</tr>
|
|
2007
|
+
<tr>
|
|
2008
|
+
<td class="col-md-4">
|
|
2009
|
+
<code>sessionStorageSync(reducer: ActionReducer, platformId?)</code>
|
|
2010
|
+
</td>
|
|
2011
|
+
</tr>
|
|
2012
|
+
|
|
2013
|
+
|
|
2014
|
+
|
|
2015
|
+
|
|
2016
|
+
<tr>
|
|
2017
|
+
<td class="col-md-4">
|
|
2018
|
+
|
|
2019
|
+
<div class="io-description">
|
|
2020
|
+
<b>Parameters :</b>
|
|
2021
|
+
|
|
2022
|
+
<table class="params">
|
|
2023
|
+
<thead>
|
|
2024
|
+
<tr>
|
|
2025
|
+
<td>Name</td>
|
|
2026
|
+
<td>Type</td>
|
|
2027
|
+
<td>Optional</td>
|
|
2028
|
+
</tr>
|
|
2029
|
+
</thead>
|
|
2030
|
+
<tbody>
|
|
2031
|
+
<tr>
|
|
2032
|
+
<td>reducer</td>
|
|
2033
|
+
<td>
|
|
2034
|
+
<code>ActionReducer</code>
|
|
2035
|
+
</td>
|
|
2036
|
+
|
|
2037
|
+
<td>
|
|
2038
|
+
No
|
|
2039
|
+
</td>
|
|
2040
|
+
|
|
2041
|
+
|
|
2042
|
+
</tr>
|
|
2043
|
+
<tr>
|
|
2044
|
+
<td>platformId</td>
|
|
2045
|
+
<td>
|
|
2046
|
+
</td>
|
|
2047
|
+
|
|
2048
|
+
<td>
|
|
2049
|
+
Yes
|
|
2050
|
+
</td>
|
|
2051
|
+
|
|
2052
|
+
|
|
2053
|
+
</tr>
|
|
2054
|
+
</tbody>
|
|
2055
|
+
</table>
|
|
2056
|
+
</div>
|
|
2057
|
+
<div class="io-description">
|
|
2058
|
+
<b>Returns : </b> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" target="_blank" >Function</a></code>
|
|
2059
|
+
|
|
2060
|
+
</div>
|
|
2061
|
+
<div class="io-description">
|
|
2062
|
+
|
|
2063
|
+
</div>
|
|
2064
|
+
</td>
|
|
2065
|
+
</tr>
|
|
2066
|
+
</tbody>
|
|
2067
|
+
</table>
|
|
1784
2068
|
</section>
|
|
1785
2069
|
|
|
1786
2070
|
|
|
@@ -329,6 +329,9 @@
|
|
|
329
329
|
<li>
|
|
330
330
|
<a href="#parentOffsetEl" title="packages/eui/packages/core/src/lib/helpers/dom-helpers.ts" ><b>parentOffsetEl</b> (packages/.../dom-helpers.ts)</a>
|
|
331
331
|
</li>
|
|
332
|
+
<li>
|
|
333
|
+
<a href="#PLATFORM_BROWSER_ID" title="packages/eui/packages/core/src/lib/services/store/store.service.mock.ts" ><b>PLATFORM_BROWSER_ID</b> (packages/.../store.service.mock.ts)</a>
|
|
334
|
+
</li>
|
|
332
335
|
<li>
|
|
333
336
|
<a href="#position" title="packages/eui/packages/core/src/lib/helpers/dom-helpers.ts" ><b>position</b> (packages/.../dom-helpers.ts)</a>
|
|
334
337
|
</li>
|
|
@@ -1393,7 +1396,7 @@
|
|
|
1393
1396
|
</tr>
|
|
1394
1397
|
<tr>
|
|
1395
1398
|
<td class="col-md-4">
|
|
1396
|
-
<i>Default value : </i><code><S extends CoreState>(reducer: ActionReducer<S>, storage: Storage) =>
|
|
1399
|
+
<i>Default value : </i><code><S extends CoreState>(reducer: ActionReducer<S>, storage: Storage | null) =>
|
|
1397
1400
|
(state: S, action: Action): S => {
|
|
1398
1401
|
if (action.type === CoreAppActionTypes.INIT_STORE) {
|
|
1399
1402
|
// This action must be dispatched from an app initializer
|
|
@@ -1401,31 +1404,32 @@
|
|
|
1401
1404
|
// If they are the same, we merge the local state into the initial state.
|
|
1402
1405
|
// If there is a mismatch, we don't merge the local state, but update only the initial state.
|
|
1403
1406
|
|
|
1404
|
-
|
|
1405
|
-
|
|
1407
|
+
if (storage) {
|
|
1408
|
+
// load the state from the localStorage
|
|
1409
|
+
const localState: S = loadState<S>(storage);
|
|
1406
1410
|
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
const payloadVersion = payload?.version;
|
|
1411
|
+
// extract the details about user and app version from the action payload
|
|
1412
|
+
const payloadVersion = (action as InitStoreAction).payload?.version;
|
|
1410
1413
|
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1414
|
+
if (localState) {
|
|
1415
|
+
// TODO: Why all these checks here? What is the purpose of this code?
|
|
1416
|
+
// extract the details about user and app version from the storage state
|
|
1417
|
+
const localVersion = localState?.app?.version;
|
|
1418
|
+
// const localUserId = localState.user && localState.user.userId;
|
|
1416
1419
|
|
|
1417
|
-
|
|
1418
|
-
|
|
1420
|
+
const isVersionOK = !localVersion || !payloadVersion || localVersion === payloadVersion;
|
|
1421
|
+
// const isUserIdOK = (localUserId === payloadUserId);
|
|
1419
1422
|
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
+
// update the entire state with deep merge of states, if the version and user are the same
|
|
1424
|
+
if (isVersionOK) {
|
|
1425
|
+
state = extend(true, {}, state, localState);
|
|
1426
|
+
}
|
|
1423
1427
|
}
|
|
1424
|
-
}
|
|
1425
1428
|
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
+
// update the app version, if defined
|
|
1430
|
+
if (payloadVersion) {
|
|
1431
|
+
state = { ...state, app: { ...state?.app, version: payloadVersion } };
|
|
1432
|
+
}
|
|
1429
1433
|
}
|
|
1430
1434
|
}
|
|
1431
1435
|
|
|
@@ -1538,7 +1542,11 @@
|
|
|
1538
1542
|
</tr>
|
|
1539
1543
|
<tr>
|
|
1540
1544
|
<td class="col-md-4">
|
|
1541
|
-
<i>Default value : </i><code><S extends CoreState>(storage: Storage = localStorage): S => {
|
|
1545
|
+
<i>Default value : </i><code><S extends CoreState>(storage: Storage | null = localStorage): S => {
|
|
1546
|
+
if (!storage) {
|
|
1547
|
+
return undefined;
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1542
1550
|
try {
|
|
1543
1551
|
// by default falls back to localStorage
|
|
1544
1552
|
const serializedState = storage.getItem('state');
|
|
@@ -3879,6 +3887,35 @@
|
|
|
3879
3887
|
</tr>
|
|
3880
3888
|
|
|
3881
3889
|
|
|
3890
|
+
</tbody>
|
|
3891
|
+
</table>
|
|
3892
|
+
</section>
|
|
3893
|
+
<h3>packages/eui/packages/core/src/lib/services/store/store.service.mock.ts</h3>
|
|
3894
|
+
<section data-compodoc="block-properties">
|
|
3895
|
+
<h3></h3> <table class="table table-sm table-bordered">
|
|
3896
|
+
<tbody>
|
|
3897
|
+
<tr>
|
|
3898
|
+
<td class="col-md-4">
|
|
3899
|
+
<a name="PLATFORM_BROWSER_ID"></a>
|
|
3900
|
+
<span class="name">
|
|
3901
|
+
<span ><b>PLATFORM_BROWSER_ID</b></span>
|
|
3902
|
+
<a href="#PLATFORM_BROWSER_ID"><span class="icon ion-ios-link"></span></a>
|
|
3903
|
+
</span>
|
|
3904
|
+
</td>
|
|
3905
|
+
</tr>
|
|
3906
|
+
<tr>
|
|
3907
|
+
<td class="col-md-4">
|
|
3908
|
+
<i>Type : </i> <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string" target="_blank" >string</a></code>
|
|
3909
|
+
|
|
3910
|
+
</td>
|
|
3911
|
+
</tr>
|
|
3912
|
+
<tr>
|
|
3913
|
+
<td class="col-md-4">
|
|
3914
|
+
<i>Default value : </i><code>'browser'</code>
|
|
3915
|
+
</td>
|
|
3916
|
+
</tr>
|
|
3917
|
+
|
|
3918
|
+
|
|
3882
3919
|
</tbody>
|
|
3883
3920
|
</table>
|
|
3884
3921
|
</section>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Injectable, Optional } from '@angular/core';
|
|
1
|
+
import { Inject, Injectable, Optional, PLATFORM_ID } from '@angular/core';
|
|
2
|
+
import { isPlatformBrowser } from '@angular/common';
|
|
2
3
|
import { StorageService } from './storage.service';
|
|
3
4
|
import * as i0 from "@angular/core";
|
|
4
5
|
import * as i1 from "../log/log.service";
|
|
@@ -7,9 +8,10 @@ import * as i1 from "../log/log.service";
|
|
|
7
8
|
*/
|
|
8
9
|
export class LocalStorageService extends StorageService {
|
|
9
10
|
static { this.NAME = 'LocalStorageService'; }
|
|
10
|
-
constructor(log) {
|
|
11
|
+
constructor(log, platformId) {
|
|
11
12
|
super();
|
|
12
13
|
this.log = log;
|
|
14
|
+
this.platformId = platformId;
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* the name of the storage service
|
|
@@ -25,15 +27,17 @@ export class LocalStorageService extends StorageService {
|
|
|
25
27
|
// TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html
|
|
26
28
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
29
|
get(key) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.log
|
|
30
|
+
if (isPlatformBrowser(this.platformId)) {
|
|
31
|
+
try {
|
|
32
|
+
const serialized = localStorage.getItem(key);
|
|
33
|
+
return serialized && JSON.parse(serialized);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
if (this.log) {
|
|
37
|
+
this.log.error(this.name(), 'get', err);
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
35
40
|
}
|
|
36
|
-
return undefined;
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
43
|
/**
|
|
@@ -44,13 +48,15 @@ export class LocalStorageService extends StorageService {
|
|
|
44
48
|
// TODO: find the correct type or turn into a generic, https://www.typescriptlang.org/docs/handbook/2/generics.html
|
|
45
49
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
50
|
set(key, value) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
this.log
|
|
51
|
+
if (isPlatformBrowser(this.platformId)) {
|
|
52
|
+
try {
|
|
53
|
+
const serialized = JSON.stringify(value);
|
|
54
|
+
localStorage.setItem(key, serialized);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
if (this.log) {
|
|
58
|
+
this.log.error(this.name(), 'set', err);
|
|
59
|
+
}
|
|
54
60
|
}
|
|
55
61
|
}
|
|
56
62
|
}
|
|
@@ -59,21 +65,26 @@ export class LocalStorageService extends StorageService {
|
|
|
59
65
|
* @param key the associated key
|
|
60
66
|
*/
|
|
61
67
|
remove(key) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
this.log
|
|
68
|
+
if (isPlatformBrowser(this.platformId)) {
|
|
69
|
+
try {
|
|
70
|
+
localStorage.removeItem(key);
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
if (this.log) {
|
|
74
|
+
this.log.error(this.name(), 'remove', err);
|
|
75
|
+
}
|
|
68
76
|
}
|
|
69
77
|
}
|
|
70
78
|
}
|
|
71
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.0", ngImport: i0, type: LocalStorageService, deps: [{ token: i1.LogService, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
79
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.0", ngImport: i0, type: LocalStorageService, deps: [{ token: i1.LogService, optional: true }, { token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
72
80
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.0", ngImport: i0, type: LocalStorageService }); }
|
|
73
81
|
}
|
|
74
82
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.0", ngImport: i0, type: LocalStorageService, decorators: [{
|
|
75
83
|
type: Injectable
|
|
76
84
|
}], ctorParameters: () => [{ type: i1.LogService, decorators: [{
|
|
77
85
|
type: Optional
|
|
86
|
+
}] }, { type: undefined, decorators: [{
|
|
87
|
+
type: Inject,
|
|
88
|
+
args: [PLATFORM_ID]
|
|
78
89
|
}] }] });
|
|
79
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
90
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9jYWwtc3RvcmFnZS5zZXJ2aWNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiO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fVxuICAgIH1cblxuICAgIC8qKlxuICAgICAqIHJlbW92ZXMgYW4gb2JqZWN0IGZyb20gbG9jYWwgc3RvcmFnZVxuICAgICAqIEBwYXJhbSBrZXkgdGhlIGFzc29jaWF0ZWQga2V5XG4gICAgICovXG4gICAgcmVtb3ZlKGtleTogc3RyaW5nKTogdm9pZCB7XG4gICAgICAgIGlmKGlzUGxhdGZvcm1Ccm93c2VyKHRoaXMucGxhdGZvcm1JZCkpIHtcbiAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgbG9jYWxTdG9yYWdlLnJlbW92ZUl0ZW0oa2V5KTtcbiAgICAgICAgICAgIH0gY2F0Y2ggKGVycikge1xuICAgICAgICAgICAgICAgIGlmICh0aGlzLmxvZykge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLmxvZy5lcnJvcih0aGlzLm5hbWUoKSwgJ3JlbW92ZScsIGVycik7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG4gICAgfVxufVxuIl19
|