1111import deepDiffer from 'deepDiffer' ;
1212import flattenStyle from 'flattenStyle' ;
1313
14+ import type { AttributeConfiguration } from './ReactNativeTypes' ;
15+
1416const emptyObject = { } ;
1517
1618/**
@@ -22,20 +24,6 @@ const emptyObject = {};
2224 * across modules, I've kept them isolated to this module.
2325 */
2426
25- type AttributeDiffer = ( prevProp : mixed , nextProp : mixed ) => boolean ;
26- type AttributePreprocessor = ( nextProp : mixed ) => mixed ;
27-
28- type CustomAttributeConfiguration =
29- | { diff : AttributeDiffer , process : AttributePreprocessor }
30- | { diff : AttributeDiffer }
31- | { process : AttributePreprocessor } ;
32-
33- type AttributeConfiguration = {
34- [ key : string ] :
35- | CustomAttributeConfiguration
36- | AttributeConfiguration /*| boolean*/ ,
37- } ;
38-
3927type NestedNode = Array < NestedNode > | Object ;
4028
4129// Tracks removed keys
@@ -55,7 +43,7 @@ function defaultDiffer(prevProp: mixed, nextProp: mixed): boolean {
5543function restoreDeletedValuesInNestedArray (
5644 updatePayload : Object ,
5745 node : NestedNode ,
58- validAttributes : AttributeConfiguration ,
46+ validAttributes : AttributeConfiguration < > ,
5947) {
6048 if ( Array . isArray ( node ) ) {
6149 let i = node . length ;
@@ -113,7 +101,7 @@ function diffNestedArrayProperty(
113101 updatePayload : null | Object ,
114102 prevArray : Array < NestedNode > ,
115103 nextArray : Array < NestedNode > ,
116- validAttributes : AttributeConfiguration ,
104+ validAttributes : AttributeConfiguration < > ,
117105) : null | Object {
118106 const minLength =
119107 prevArray . length < nextArray . length ? prevArray . length : nextArray . length ;
@@ -151,7 +139,7 @@ function diffNestedProperty(
151139 updatePayload : null | Object ,
152140 prevProp : NestedNode ,
153141 nextProp : NestedNode ,
154- validAttributes : AttributeConfiguration ,
142+ validAttributes : AttributeConfiguration < > ,
155143) : null | Object {
156144 if ( ! updatePayload && prevProp === nextProp ) {
157145 // If no properties have been added, then we can bail out quickly on object
@@ -212,7 +200,7 @@ function diffNestedProperty(
212200function addNestedProperty (
213201 updatePayload : null | Object ,
214202 nextProp : NestedNode ,
215- validAttributes : AttributeConfiguration ,
203+ validAttributes : AttributeConfiguration < > ,
216204) {
217205 if ( ! nextProp ) {
218206 return updatePayload ;
@@ -242,7 +230,7 @@ function addNestedProperty(
242230function clearNestedProperty (
243231 updatePayload : null | Object ,
244232 prevProp : NestedNode ,
245- validAttributes : AttributeConfiguration ,
233+ validAttributes : AttributeConfiguration < > ,
246234) : null | Object {
247235 if ( ! prevProp ) {
248236 return updatePayload ;
@@ -274,9 +262,9 @@ function diffProperties(
274262 updatePayload : null | Object ,
275263 prevProps : Object ,
276264 nextProps : Object ,
277- validAttributes : AttributeConfiguration ,
265+ validAttributes : AttributeConfiguration < > ,
278266) : null | Object {
279- let attributeConfig : ? ( CustomAttributeConfiguration | AttributeConfiguration ) ;
267+ let attributeConfig ;
280268 let nextProp ;
281269 let prevProp ;
282270
@@ -375,13 +363,13 @@ function diffProperties(
375363 updatePayload ,
376364 prevProp ,
377365 nextProp ,
378- ( ( attributeConfig : any ) : AttributeConfiguration ) ,
366+ ( ( attributeConfig : any ) : AttributeConfiguration < > ) ,
379367 ) ;
380368 if ( removedKeyCount > 0 && updatePayload ) {
381369 restoreDeletedValuesInNestedArray (
382370 updatePayload ,
383371 nextProp ,
384- ( ( attributeConfig : any ) : AttributeConfiguration ) ,
372+ ( ( attributeConfig : any ) : AttributeConfiguration < > ) ,
385373 ) ;
386374 removedKeys = null ;
387375 }
@@ -432,7 +420,7 @@ function diffProperties(
432420 updatePayload = clearNestedProperty (
433421 updatePayload ,
434422 prevProp ,
435- ( ( attributeConfig : any ) : AttributeConfiguration ) ,
423+ ( ( attributeConfig : any ) : AttributeConfiguration < > ) ,
436424 ) ;
437425 }
438426 }
@@ -445,7 +433,7 @@ function diffProperties(
445433function addProperties (
446434 updatePayload : null | Object ,
447435 props : Object ,
448- validAttributes : AttributeConfiguration ,
436+ validAttributes : AttributeConfiguration < > ,
449437) : null | Object {
450438 // TODO: Fast path
451439 return diffProperties ( updatePayload , emptyObject , props , validAttributes ) ;
@@ -458,15 +446,15 @@ function addProperties(
458446function clearProperties (
459447 updatePayload : null | Object ,
460448 prevProps : Object ,
461- validAttributes : AttributeConfiguration ,
449+ validAttributes : AttributeConfiguration < > ,
462450) : null | Object {
463451 // TODO: Fast path
464452 return diffProperties ( updatePayload , prevProps , emptyObject , validAttributes ) ;
465453}
466454
467455export function create (
468456 props : Object ,
469- validAttributes : AttributeConfiguration ,
457+ validAttributes : AttributeConfiguration < > ,
470458) : null | Object {
471459 return addProperties (
472460 null , // updatePayload
@@ -478,7 +466,7 @@ export function create(
478466export function diff (
479467 prevProps : Object ,
480468 nextProps : Object ,
481- validAttributes : AttributeConfiguration ,
469+ validAttributes : AttributeConfiguration < > ,
482470) : null | Object {
483471 return diffProperties (
484472 null , // updatePayload
0 commit comments