@@ -2,6 +2,18 @@ import _ from 'lodash'
2
2
import cx from 'classnames'
3
3
import React , { cloneElement , isValidElement } from 'react'
4
4
5
+ // Simplified and faster version of:
6
+ // http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery
7
+ const hashCode = function hashCode ( str ) {
8
+ const { length } = str
9
+ if ( ! str || length === 0 ) return 0
10
+ let hash = 0
11
+ for ( let i = 0 ; i < length ; i ++ ) {
12
+ hash = hash * 31 + str . charCodeAt ( i ) | 0
13
+ }
14
+ return hash
15
+ }
16
+
5
17
/**
6
18
* Merges props and classNames.
7
19
*
@@ -16,8 +28,14 @@ const mergePropsAndClassName = (defaultProps, props) => {
16
28
newProps . className = cx ( defaultProps . className , props . className ) // eslint-disable-line react/prop-types
17
29
}
18
30
19
- if ( ! newProps . key && childKey ) {
20
- newProps . key = _ . isFunction ( childKey ) ? childKey ( newProps ) : childKey
31
+ if ( ! newProps . key ) {
32
+ if ( childKey ) {
33
+ newProps . key = _ . isFunction ( childKey ) ? childKey ( newProps ) : childKey
34
+ } else {
35
+ const stringified = _ . map ( newProps , ( val , key ) => `${ key } :${ val } ` ) . join ( '' )
36
+ console . log ( stringified )
37
+ newProps . key = hashCode ( stringified )
38
+ }
21
39
}
22
40
23
41
return newProps
@@ -57,6 +75,10 @@ export function createShorthand(Component, mapValueToProps, val, defaultProps =
57
75
defaultProps = _ . isFunction ( defaultProps ) ? defaultProps ( usersProps ) : defaultProps
58
76
const props = mergePropsAndClassName ( defaultProps , usersProps )
59
77
78
+ if ( Component . _meta . name === 'TableCell' ) {
79
+ console . log ( props )
80
+ }
81
+
60
82
// Clone ReactElements
61
83
if ( type === 'element' ) {
62
84
return cloneElement ( val , props )
0 commit comments