File tree 3 files changed +31
-3
lines changed
3 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -36,14 +36,19 @@ function hashKey(obj, nextUidFn) {
36
36
/**
37
37
* HashMap which can use objects as keys
38
38
*/
39
- function HashMap ( array , isolatedUid ) {
39
+ function HashMap ( seedData , isolatedUid ) {
40
40
if ( isolatedUid ) {
41
41
var uid = 0 ;
42
42
this . nextUid = function ( ) {
43
43
return ++ uid ;
44
44
} ;
45
45
}
46
- forEach ( array , this . put , this ) ;
46
+
47
+ if ( seedData ) {
48
+ var putFn = isArray ( seedData ) ?
49
+ this . put : reverseParams ( this . put . bind ( this ) ) ;
50
+ forEach ( seedData , putFn , this ) ;
51
+ }
47
52
}
48
53
HashMap . prototype = {
49
54
/**
@@ -63,6 +68,14 @@ HashMap.prototype = {
63
68
return this [ hashKey ( key , this . nextUid ) ] ;
64
69
} ,
65
70
71
+ /**
72
+ * @param key
73
+ * @returns {boolean } whether a value is stored under the specified key
74
+ */
75
+ has : function ( key ) {
76
+ return this . hasOwnProperty ( hashKey ( key , this . nextUid ) ) ;
77
+ } ,
78
+
66
79
/**
67
80
* Remove the key/value pair
68
81
* @param key
Original file line number Diff line number Diff line change @@ -563,8 +563,11 @@ var selectDirective = function() {
563
563
// Write value now needs to set the selected property of each matching option
564
564
selectCtrl . writeValue = function writeMultipleValue ( value ) {
565
565
var items = new HashMap ( value ) ;
566
+ var selectValueMap = selectCtrl . selectValueMap ;
567
+
566
568
forEach ( element . find ( 'option' ) , function ( option ) {
567
- option . selected = isDefined ( items . get ( option . value ) ) || isDefined ( items . get ( selectCtrl . selectValueMap [ option . value ] ) ) ;
569
+ var value = option . value ;
570
+ option . selected = items . has ( value ) || items . has ( selectValueMap [ value ] ) ;
568
571
} ) ;
569
572
} ;
570
573
Original file line number Diff line number Diff line change @@ -8,11 +8,16 @@ describe('api', function() {
8
8
var key = { } ;
9
9
var value1 = { } ;
10
10
var value2 = { } ;
11
+
11
12
map . put ( key , value1 ) ;
12
13
map . put ( key , value2 ) ;
14
+
15
+ expect ( map . has ( key ) ) . toBe ( true ) ;
16
+ expect ( map . has ( { } ) ) . toBe ( false ) ;
13
17
expect ( map . get ( key ) ) . toBe ( value2 ) ;
14
18
expect ( map . get ( { } ) ) . toBeUndefined ( ) ;
15
19
expect ( map . remove ( key ) ) . toBe ( value2 ) ;
20
+ expect ( map . has ( key ) ) . toBe ( false ) ;
16
21
expect ( map . get ( key ) ) . toBeUndefined ( ) ;
17
22
} ) ;
18
23
@@ -23,6 +28,13 @@ describe('api', function() {
23
28
expect ( map . get ( 'c' ) ) . toBeUndefined ( ) ;
24
29
} ) ;
25
30
31
+ it ( 'should init from an object' , function ( ) {
32
+ var map = new HashMap ( { a : 'foo' , b : 'bar' } ) ;
33
+ expect ( map . get ( 'a' ) ) . toBe ( 'foo' ) ;
34
+ expect ( map . get ( 'b' ) ) . toBe ( 'bar' ) ;
35
+ expect ( map . get ( 'c' ) ) . toBeUndefined ( ) ;
36
+ } ) ;
37
+
26
38
it ( 'should maintain hashKey for object keys' , function ( ) {
27
39
var map = new HashMap ( ) ;
28
40
var key = { } ;
You can’t perform that action at this time.
0 commit comments