@@ -24,6 +24,7 @@ npm install @ngx-pwa/local-storage@next
24
24
```
25
25
26
26
2 . Start your project: problems will be seen at compilation.
27
+ Or you could search for ` getItem ` as most breaking changes are about its options.
27
28
28
29
## The bad part: breaking changes
29
30
@@ -41,12 +42,17 @@ Also, `JSONSchemaNull` is removed.
41
42
42
43
Before v8, ` type ` was optional:
43
44
``` typescript
44
- this .localStorage .getItem (' test' , { schema: { items: { type: ' string' } } })
45
+ this .localStorage .getItem (' test' , { schema: {
46
+ items: { type: ' string' }
47
+ } })
45
48
```
46
49
47
50
Since v8:
48
51
``` typescript
49
- this .localStorage .getItem (' test' , { schema: { type: ' array' , items: { type: ' string' } } })
52
+ this .localStorage .getItem (' test' , {
53
+ type: ' array' ,
54
+ items: { type: ' string' }
55
+ })
50
56
```
51
57
52
58
Also, ` items ` no longer accepts an array of JSON schemas, meaning arrays with multiple types
@@ -58,16 +64,21 @@ are no longer possible (and it's better for consistency, use an object if you mi
58
64
59
65
Before v8, ` type ` was optional:
60
66
``` typescript
61
- this .localStorage .getItem (' test' , { schema: { properties: {
62
- test: { type: ' string' }
63
- } } })
67
+ this .localStorage .getItem (' test' , { schema: {
68
+ properties: {
69
+ test: { type: ' string' }
70
+ }
71
+ } })
64
72
```
65
73
66
74
Since v8:
67
75
``` typescript
68
- this .localStorage .getItem (' test' , { schema: { type: ' object' , properties: {
69
- test: { type: ' string' }
70
- } } })
76
+ this .localStorage .getItem (' test' , {
77
+ type: ' object' ,
78
+ properties: {
79
+ test: { type: ' string' }
80
+ }
81
+ })
71
82
```
72
83
73
84
### Validation of constants
@@ -82,7 +93,7 @@ this.localStorage.getItem('test', { schema: { const: 'value' } })
82
93
83
94
Since v8:
84
95
``` typescript
85
- this .localStorage .getItem (' test' , { schema: { type: ' string' , const: ' value' } })
96
+ this .localStorage .getItem (' test' , { type: ' string' , const: ' value' })
86
97
```
87
98
88
99
Also, ` JSONSchemaConst ` interface is removed.
@@ -99,7 +110,7 @@ this.localStorage.getItem('test', { schema: { enum: ['value 1', 'value 2'] } })
99
110
100
111
Since v8:
101
112
``` typescript
102
- this .localStorage .getItem (' test' , { schema: { type: ' string' , enum: [' value 1' , ' value 2' ] } })
113
+ this .localStorage .getItem (' test' , { type: ' string' , enum: [' value 1' , ' value 2' ] })
103
114
```
104
115
105
116
It also means enums of different types are no longer possible (and it's better for consistency).
@@ -119,15 +130,28 @@ While not recommended, you can still force it:
119
130
this .localStorage .getItem (' test' , { schema: someSchema as any })
120
131
```
121
132
122
-
123
133
## The good part: simplication changes
124
134
125
- The following changes are not required. Previous code will still work,
126
- but ** for new code, follow these new guidelines** .
135
+ The following changes are not required but strongly recommended.
136
+ ** Previous code will still work** , but * for new code, follow these new guidelines* .
137
+
138
+ ### Easier API for ` getItem() `
139
+
140
+ ` getItem() ` API has been simplified: the secong argument is now directly the schema for validation.
141
+
142
+ Before v8:
143
+ ``` typescript
144
+ this .localStorage .getItem <string >(' test' , { schema: { type: ' string' } })
145
+ ```
146
+
147
+ Since v8:
148
+ ``` typescript
149
+ this .localStorage .getItem (' test' , { type: ' string' })
150
+ ```
127
151
128
152
### Cast now inferred!
129
153
130
- The returned type of ` getItem() ` is now inferred for basic types (` string ` , ` number ` , ` boolean ` )
154
+ The previous change allows that the returned type of ` getItem() ` is now inferred for basic types (` string ` , ` number ` , ` boolean ` )
131
155
and arrays of basic types (` string[] ` , ` number[] ` , ` boolean[] ` ).
132
156
133
157
Before v8:
@@ -143,21 +167,21 @@ this.localStorage.getItem<string>('test', { schema: { type: 'string' } }).subscr
143
167
144
168
Since v8:
145
169
``` typescript
146
- this .localStorage .getItem (' test' , { schema: { type: ' string' } }).subscribe ((data ) => {
170
+ this .localStorage .getItem (' test' , { type: ' string' }).subscribe ((data ) => {
147
171
data ; // string :D
148
172
});
149
173
```
150
174
151
- Cast is still needed for objects. Follow the [ validation guide] ( ./VALIDATION.md ) .
175
+ Cast is still needed for objects. Follow the new [ validation guide] ( ./VALIDATION.md ) .
152
176
153
177
### Use the generic ` JSONSchema `
154
178
155
- Now the ` JSONSchema ` interface has been refactored, just use this one,
156
- and avoid the specific ones (` JSONSchemaString ` , ` JSONSchemaBoolean ` and so on).
179
+ Now the ` JSONSchema ` interface has been refactored, just use this one.
157
180
IntelliSense will adjust itself based on the ` type ` option.
181
+ The specific interfaces (` JSONSchemaString ` , ` JSONSchemaBoolean ` and so on) are still there but useless.
158
182
159
183
` JSONSchemaNumeric ` still works but is deprecated in favor of ` JSONSchemaNumber ` or ` JSONSchemaInteger `
160
- (but again, just use ` JSONSchema ` )
184
+ (but again, just use ` JSONSchema ` ).
161
185
162
186
## More documentation
163
187
0 commit comments