more docs and refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-10-07 15:09:36 +03:00
parent 27234942c3
commit 5816bf779d
3 changed files with 33 additions and 4 deletions

View File

@ -49,11 +49,13 @@ A library of JavaScript type extensions, types and type utilities.
- [`<unique-key-map>.set(..)`](#unique-key-mapset)
- [`<unique-key-map>.reset(..)`](#unique-key-mapreset)
- [`<unique-key-map>.rename(..)`](#unique-key-maprename)
- [`<unique-key-map>.orderedRename(..)`](#unique-key-maporderedrename)
- [`<unique-key-map>.unorderedRename(..)`](#unique-key-mapunorderedrename)
- [`<unique-key-map>.keysOf(..)`](#unique-key-mapkeysof)
- [`<unique-key-map>.originalKey(..)`](#unique-key-maporiginalkey)
- [`<unique-key-map>.uniqueKey(..)`](#unique-key-mapuniquekey)
- [`<unique-key-map>.__key_pattern__`](#unique-key-map__key_pattern__)
- [`<unique-key-map>.__unordered_rename__`](#unique-key-map__unordered_rename__)
- [License](#license)
## Installation
@ -329,6 +331,25 @@ Explicitly write an `<item>` under `<key>` as-is, this is like `Map`'s `.set(..)
#### `<unique-key-map>.rename(..)`
```
<unique-key-map>.rename(<from-key>, <to-key>)
-> <unique-key-map>
<unique-key-map>.rename(<from-key>, <to-key>, true)
-> <new-key>
```
Rename item key from `<from-key>` to `<to-key>`.
Same mechanics apply as for [`.set(..)`](#unique-key-mapset) for key uniqueness.
Note, if [`.__unordered_rename__`](#unique-key-map__unordered_rename__) is
`false` (default) this calls [`.orderedRename(..)`](#unique-key-maporderedrename)
otherwise [`.unorderedRename(..)`](#unique-key-mapunorderedrename) is called.
#### `<unique-key-map>.orderedRename(..)`
#### `<unique-key-map>.unorderedRename(..)`
#### `<unique-key-map>.keysOf(..)`
@ -339,6 +360,8 @@ Explicitly write an `<item>` under `<key>` as-is, this is like `Map`'s `.set(..)
#### `<unique-key-map>.__key_pattern__`
#### `<unique-key-map>.__unordered_rename__`
## License

View File

@ -58,7 +58,6 @@ module.UniqueKeyMap = object.Constructor('UniqueKeyMap', Map, {
//
__unique_key_value__: false,
__unorderd_writes__: false,
// helpers...
@ -154,12 +153,13 @@ module.UniqueKeyMap = object.Constructor('UniqueKeyMap', Map, {
s.size == 0
&& this.__keys.delete(this.get(key)) }
return object.parentCall(UniqueKeyMap.prototype, 'delete', this, key) },
// NOTE: this maintains the item order. This is done by rewriting
// items in sequence, this may be slow and trigger lots of write
// observer callbacks. to avoid this use .unOrderedRename(..)
// XXX do not see how can we avoid rewriting the map if we want to
// keep order...
rename: function(from, to, return_key=false){
orderedRename: function(from, to, return_key=false){
var keys = [...this.keys()]
// rename the element...
var e = this.get(from)
@ -171,11 +171,17 @@ module.UniqueKeyMap = object.Constructor('UniqueKeyMap', Map, {
return return_key ?
n
: this },
// NOTE: this affects order...
// NOTE: the renamed item is appended to the map...
unorderedRename: function(from, to, return_key=false){
var e = this.get(from)
this.delete(from)
return this.set(to, e, return_key) },
__unorderd_rename__: false,
rename: function(from, to, return_key=false){
return this.__unorderd_writes__ ?
this.unorderedRename(...arguments)
: this.orderedRename(...arguments) },
})

View File

@ -1,6 +1,6 @@
{
"name": "ig-types",
"version": "2.0.11",
"version": "2.0.12",
"description": "Generic JavaScript types and type extensions...",
"main": "main.js",
"scripts": {