Browse Source

The method `WebStorage.putObjectIfAbsent()` is now generic

tags/v1.0.4
Cédric Belin 2 months ago
parent
commit
c9fc5c6961
3 changed files with 3 additions and 3 deletions
  1. +1
    -1
      doc/usage/api.md
  2. +1
    -1
      lib/index.d.ts
  3. +1
    -1
      src/webstorage/WebStorage.hx

+ 1
- 1
doc/usage/api.md View File

@@ -299,7 +299,7 @@ Otherwise calls `ifAbsent` to get a new value, associates the key to that value,
console.log(value); // "bar"
}

## **putObjectIfAbsent**(key: String, ifAbsent: () -> Dynamic): Dynamic
## **putObjectIfAbsent**<T>(key: String, ifAbsent: () -> T): Null<T>
Looks up the value of the specified key, or add a new value if it isn't there.

Returns the deserialized value associated to the key, if there is one.


+ 1
- 1
lib/index.d.ts View File

@@ -9,7 +9,7 @@ export declare abstract class WebStorage extends EventTarget implements Iterable
get(key: string, defaultValue?: string): string|undefined;
getObject<T>(key: string, defaultValue?: T): T|undefined;
putIfAbsent(key: string, ifAbsent: () => string): string;
putObjectIfAbsent(key: string, ifAbsent: () => any): any;
putObjectIfAbsent<T>(key: string, ifAbsent: () => T): T|undefined;
remove(key: string): string|undefined;
set(key: string, value: string): this;
setObject(key: string, value: unknown): this;


+ 1
- 1
src/webstorage/WebStorage.hx View File

@@ -96,7 +96,7 @@ import js.lib.Symbol;
Returns the deserialized value associated to `key`, if there is one.
Otherwise calls `ifAbsent` to get a new value, serializes and associates `key` to that value, and then returns the new value.
**/
public function putObjectIfAbsent(key: String, ifAbsent: () -> Dynamic): Dynamic {
public function putObjectIfAbsent<T>(key: String, ifAbsent: () -> T): Null<T> {
if (!exists(key)) setObject(key, ifAbsent());
return getObject(key);
}


Loading…
Cancel
Save