Skip to content

Commit a0174cd

Browse files
committed
feat: adds “order” to useTransition
1 parent f86c185 commit a0174cd

File tree

4 files changed

+99
-82
lines changed

4 files changed

+99
-82
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ $RECYCLE.BIN/
1010
.docz/
1111
package-lock.json
1212
coverage/
13+
.idea

.size-snapshot.json

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919
"gzipped": 1999
2020
},
2121
"dist/web.js": {
22-
"bundled": 62572,
23-
"minified": 29807,
24-
"gzipped": 10770,
22+
"bundled": 63145,
23+
"minified": 29904,
24+
"gzipped": 10821,
2525
"treeshaked": {
2626
"rollup": {
27-
"code": 11662,
27+
"code": 11570,
2828
"import_statements": 242
2929
},
3030
"webpack": {
31-
"code": 12820
31+
"code": 12729
3232
}
3333
}
3434
},
@@ -38,23 +38,23 @@
3838
"gzipped": 11641
3939
},
4040
"dist/native.js": {
41-
"bundled": 59631,
42-
"minified": 27780,
43-
"gzipped": 9734,
41+
"bundled": 60235,
42+
"minified": 27907,
43+
"gzipped": 9786,
4444
"treeshaked": {
4545
"rollup": {
46-
"code": 8536,
46+
"code": 8455,
4747
"import_statements": 180
4848
},
4949
"webpack": {
50-
"code": 10132
50+
"code": 10051
5151
}
5252
}
5353
},
5454
"dist/universal.js": {
55-
"bundled": 47027,
56-
"minified": 21018,
57-
"gzipped": 6917,
55+
"bundled": 47600,
56+
"minified": 21121,
57+
"gzipped": 6962,
5858
"treeshaked": {
5959
"rollup": {
6060
"code": 523,
@@ -66,16 +66,16 @@
6666
}
6767
},
6868
"dist/konva.js": {
69-
"bundled": 58216,
70-
"minified": 27035,
71-
"gzipped": 9647,
69+
"bundled": 58789,
70+
"minified": 27138,
71+
"gzipped": 9697,
7272
"treeshaked": {
7373
"rollup": {
74-
"code": 9212,
74+
"code": 9114,
7575
"import_statements": 242
7676
},
7777
"webpack": {
78-
"code": 10368
78+
"code": 10270
7979
}
8080
}
8181
},
@@ -202,14 +202,14 @@
202202
}
203203
},
204204
"dist/web.cjs.js": {
205-
"bundled": 72193,
206-
"minified": 34043,
207-
"gzipped": 11352
205+
"bundled": 72315,
206+
"minified": 33923,
207+
"gzipped": 11405
208208
},
209209
"dist/native.cjs.js": {
210-
"bundled": 69762,
211-
"minified": 32200,
212-
"gzipped": 10323
210+
"bundled": 69916,
211+
"minified": 32097,
212+
"gzipped": 10380
213213
},
214214
"dist/renderprops.cjs.js": {
215215
"bundled": 77632,
@@ -237,9 +237,9 @@
237237
"gzipped": 10452
238238
},
239239
"dist/universal.cjs.js": {
240-
"bundled": 56293,
241-
"minified": 25104,
242-
"gzipped": 7490
240+
"bundled": 56415,
241+
"minified": 24980,
242+
"gzipped": 7536
243243
},
244244
"dist/test.js": {
245245
"bundled": 32365,
@@ -261,8 +261,8 @@
261261
"gzipped": 5405
262262
},
263263
"dist/konva.cjs.js": {
264-
"bundled": 67598,
265-
"minified": 31193,
266-
"gzipped": 10231
264+
"bundled": 67720,
265+
"minified": 31069,
266+
"gzipped": 10288
267267
}
268268
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "react-spring",
2+
"name": "@morgs32/react-spring",
33
"version": "8.0.7",
44
"description": "A set of spring-physics based animation primitives",
55
"main": "web.cjs.js",

src/useTransition.js

Lines changed: 67 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ function diffItems({ first, prevProps, ...state }, props) {
160160
trail = 0,
161161
unique,
162162
config,
163+
order = ['added', 'removed', 'updated'],
163164
} = get(props)
164165
let { keys: _keys, items: _items } = get(prevProps)
165166
let current = { ...state.current }
@@ -174,62 +175,77 @@ function diffItems({ first, prevProps, ...state }, props) {
174175
.filter(item => !item.destroyed && !nextSet.has(item.originalKey))
175176
.map(i => i.originalKey)
176177
let updated = keys.filter(item => currentSet.has(item))
177-
let delay = 0
178+
let delay = -trail
178179

179-
added.forEach((key, index) => {
180-
// In unique mode, remove fading out transitions if their key comes in again
181-
if (unique && deleted.find(d => d.originalKey === key))
182-
deleted = deleted.filter(t => t.originalKey !== key)
180+
while (order.length) {
181+
const changeType = order.shift()
183182

184-
// TODO: trail shouldn't apply to the first item, no matter if it's enter, leave or update!
185-
const keyIndex = keys.indexOf(key)
186-
const item = items[keyIndex]
187-
const slot = first && initial !== void 0 ? 'initial' : 'enter'
188-
current[key] = {
189-
slot,
190-
originalKey: key,
191-
key: unique ? String(key) : guid++,
192-
item,
193-
trail: (delay = delay + (index > 0 ? trail : 0)),
194-
config: callProp(config, item, slot),
195-
from: callProp(
196-
first ? (initial !== void 0 ? initial || {} : from) : from,
197-
item
198-
),
199-
to: callProp(enter, item),
200-
}
201-
})
183+
switch (changeType) {
202184

203-
removed.forEach(key => {
204-
const keyIndex = _keys.indexOf(key)
205-
const item = _items[keyIndex]
206-
const slot = 'leave'
207-
deleted.unshift({
208-
...current[key],
209-
slot,
210-
destroyed: true,
211-
left: _keys[Math.max(0, keyIndex - 1)],
212-
right: _keys[Math.min(_keys.length, keyIndex + 1)],
213-
trail: (delay = delay + trail),
214-
config: callProp(config, item, slot),
215-
to: callProp(leave, item),
216-
})
217-
delete current[key]
218-
})
185+
case 'added': {
186+
added.forEach((key, index) => {
187+
// In unique mode, remove fading out transitions if their key comes in again
188+
if (unique && deleted.find(d => d.originalKey === key))
189+
deleted = deleted.filter(t => t.originalKey !== key)
219190

220-
updated.forEach(key => {
221-
const keyIndex = keys.indexOf(key)
222-
const item = items[keyIndex]
223-
const slot = 'update'
224-
current[key] = {
225-
...current[key],
226-
item,
227-
slot,
228-
trail: (delay = delay + trail),
229-
config: callProp(config, item, slot),
230-
to: callProp(update, item),
191+
// TODO: trail shouldn't apply to the first item, no matter if it's enter, leave or update!
192+
const keyIndex = keys.indexOf(key)
193+
const item = items[keyIndex]
194+
const slot = first && initial !== void 0 ? 'initial' : 'enter'
195+
current[key] = {
196+
slot,
197+
originalKey: key,
198+
key: unique ? String(key) : guid++,
199+
item,
200+
trail: (delay = delay + trail),
201+
config: callProp(config, item, slot),
202+
from: callProp(
203+
first ? (initial !== void 0 ? initial || {} : from) : from,
204+
item
205+
),
206+
to: callProp(enter, item),
207+
}
208+
})
209+
break
210+
}
211+
case 'removed': {
212+
removed.forEach(key => {
213+
const keyIndex = _keys.indexOf(key)
214+
const item = _items[keyIndex]
215+
const slot = 'leave'
216+
deleted.unshift({
217+
...current[key],
218+
slot,
219+
destroyed: true,
220+
left: _keys[Math.max(0, keyIndex - 1)],
221+
right: _keys[Math.min(_keys.length, keyIndex + 1)],
222+
trail: (delay = delay + trail),
223+
config: callProp(config, item, slot),
224+
to: callProp(leave, item),
225+
})
226+
delete current[key]
227+
})
228+
break
229+
}
230+
case 'updated': {
231+
updated.forEach(key => {
232+
const keyIndex = keys.indexOf(key)
233+
const item = items[keyIndex]
234+
const slot = 'update'
235+
current[key] = {
236+
...current[key],
237+
item,
238+
slot,
239+
trail: (delay = delay + trail),
240+
config: callProp(config, item, slot),
241+
to: callProp(update, item),
242+
}
243+
})
244+
break
245+
}
231246
}
232-
})
247+
}
248+
233249

234250
let out = keys.map(key => current[key])
235251

0 commit comments

Comments
 (0)