Skip to content

feat: useTransition rewrite #809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
44f9831
feat: rework useTransition
aleclarson Jul 10, 2019
2ea13d0
refactor: remove pointless useDiff function
aleclarson Jul 10, 2019
2b5d1c2
fix: "initial" prop
aleclarson Jul 10, 2019
84c23ed
fix: avoid "const enum" for now
aleclarson Jul 10, 2019
14e9bf9
feat: add "key" prop
aleclarson Jul 11, 2019
b641837
feat: add "sort" prop
aleclarson Jul 11, 2019
0d6958a
refactor: use "each" helper
aleclarson Jul 11, 2019
c67157c
refactor: make "transition.key" always exist
aleclarson Jul 12, 2019
dddeabc
fix: use "transition.key" when string or number
aleclarson Jul 12, 2019
814b243
refactor: rename variable
aleclarson Jul 12, 2019
fb070b4
fix: always respect item order
aleclarson Jul 12, 2019
f1cf028
fix: clear expiration timeouts on dismount
aleclarson Jul 12, 2019
8ab10ff
wip: useTransition types
aleclarson Jul 27, 2019
0b24f76
fix: type errors in useTransition
aleclarson Sep 9, 2019
7a84418
fix: add default props to useTransition
aleclarson Sep 11, 2019
ffffbf7
fix: call useLayoutEffect in useTransition
aleclarson Sep 14, 2019
9d6f6fc
nit: fix type error
aleclarson Sep 14, 2019
aa374f4
types: update useTransition types
aleclarson Sep 18, 2019
9cd633f
feat: add warning to useTransition for "keys" prop
aleclarson Sep 18, 2019
d547c4f
chore: canary release
aleclarson Sep 29, 2019
5ceecce
chore: tweak scripts/prepare.js
aleclarson Sep 29, 2019
fe17b80
build: remove "preDistTag" from lerna.json
aleclarson Sep 29, 2019
7c9b218
build: remove "from-package" for lerna publish
aleclarson Sep 29, 2019
411084c
build: fix lerna version issue
aleclarson Sep 29, 2019
c617404
chore: ship it 🚀
aleclarson Sep 29, 2019
ec151a0
fix: never set "expiresBy" for non-idle transitions
aleclarson Sep 29, 2019
010dfdb
fix: avoid calling "useLayoutEffect" when SSR
aleclarson Sep 29, 2019
56174de
build: never use caret ranges with canary and beta versions
aleclarson Sep 29, 2019
85b515e
chore: ship it 🚀
aleclarson Sep 29, 2019
d7e5b4e
fix: use "frameLoop.onFrame" in Parallax
aleclarson Sep 30, 2019
d423a84
build: use @babel/runtime/regenerator
aleclarson Sep 30, 2019
deb1e16
chore: add --canary flag to "yarn release"
aleclarson Sep 30, 2019
99c3827
chore: ship it 🚀
aleclarson Sep 30, 2019
0637589
fix: make "keys" a valid useTransition prop
aleclarson Oct 2, 2019
1ab611c
9.0.0-canary.809.4.a637589
aleclarson Oct 3, 2019
52abf08
chore: add --no-clean to "yarn release"
aleclarson Oct 3, 2019
13b904e
chore: remove extraneous "yarn prepare" call
aleclarson Oct 3, 2019
66abac1
types: avoid issue with rollup-plugin-dts
aleclarson Oct 3, 2019
a90f0be
cli: properly handle "sade.parse" return value
aleclarson Oct 3, 2019
b0b5c4e
chore: run "test:ts" script during prepare phase
aleclarson Oct 3, 2019
3cee328
cli: add --dry-run to "yarn release"
aleclarson Oct 3, 2019
f01ecc2
chore: fix "test:ts" script
aleclarson Oct 3, 2019
652955e
9.0.0-canary.809.5.f01ecc2
aleclarson Oct 3, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ React 16.8+ has global state to support its "hooks" feature, so you need to ensu

# Publishing

Run `yarn bump` to analyze commits and increment the version of any updated packages.
To publish a new version:

Run `yarn release` to publish any packages with a new version.
```
yarn release
```

To publish a **canary** version:

```
yarn release --canary
```
6 changes: 2 additions & 4 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "9.0.0-beta.34",
"version": "9.0.0-canary.809.5.f01ecc2",
"npmClient": "yarn",
"useWorkspaces": true,
"registry": "https://registry.npmjs.org",
Expand All @@ -17,10 +17,8 @@
"push": false
},
"publish": {
"bump": "from-package",
"contents": "dist",
"ignoreScripts": true,
"preDistTag": "next"
"ignoreScripts": true
}
}
}
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@
},
"scripts": {
"build": "bic",
"bump": "lerna version && yarn --force",
"clean": "lerna exec --parallel --no-bail -- rimraf node_modules dist .rpt2_cache .bic_cache",
"prepare": "node ./scripts/prepare.js && bic",
"release": "lerna publish",
"prepare": "node ./scripts/prepare.js && bic && yarn test:ts",
"release": "node ./scripts/release.js",
"test": "jest",
"test:cov": "jest --coverage",
"test:ts": "cd packages/react-spring && tsc -p . --noEmit"
Expand All @@ -66,6 +65,8 @@
"@types/react": "^16.8.19",
"build-if-changed": "^1.5.0",
"chalk": "^2.4.2",
"enquirer": "^2.3.2",
"execa": "^2.0.4",
"fs-extra": "7.0.1",
"husky": "1.3.1",
"jest": "^24.8.0",
Expand All @@ -84,6 +85,7 @@
"rollup-plugin-node-resolve": "4.0.0",
"rollup-plugin-terser": "5.0.0",
"rollup-plugin-typescript2": "0.21.1",
"sade": "^1.6.1",
"sort-package-json": "1.22.1",
"spec.ts": "1.1.3",
"ts-jest": "^24.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/addons/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-spring/addons",
"version": "next",
"version": "9.0.0-canary.809.5.f01ecc2",
"main": "src/index.ts",
"dependencies": {
"@react-spring/animated": "link:../animated",
Expand Down
6 changes: 3 additions & 3 deletions packages/addons/src/parallax.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React, {
useEffect,
CSSProperties,
} from 'react'
import { requestAnimationFrame, defaultElement as View } from 'shared/globals'
import { frameLoop, defaultElement as View } from 'shared/globals'
import { Controller, SpringConfig, config as configs } from '@react-spring/core'
import { withAnimated } from '@react-spring/animated'
import { useMemoOne } from 'use-memo-one'
Expand Down Expand Up @@ -239,7 +239,7 @@ export const Parallax = React.memo(
if (!state.busy) {
state.busy = true
state.current = event.target[getScrollType(horizontal)]
requestAnimationFrame(() => {
frameLoop.onFrame(() => {
state.layers.forEach(layer =>
layer.setPosition(state.space, state.current)
)
Expand All @@ -254,7 +254,7 @@ export const Parallax = React.memo(

const onResize = () => {
const update = () => state.update()
requestAnimationFrame(update)
frameLoop.onFrame(update)
setTimeout(update, 150) // Some browsers don't fire on maximize!
}

Expand Down
2 changes: 1 addition & 1 deletion packages/animated/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-spring/animated",
"version": "next",
"version": "9.0.0-canary.809.5.f01ecc2",
"description": "Animated component props for React",
"main": "src/index.ts",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-spring/core",
"version": "next",
"version": "9.0.0-canary.809.5.f01ecc2",
"main": "src/index.ts",
"scripts": {
"build": "rollup -c",
Expand Down
82 changes: 0 additions & 82 deletions packages/core/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,88 +109,6 @@ export function interpolateTo<T extends object>(props: T): InterpolateTo<T> {
return out
}

type ItemKey = number | string

interface Item {
key: ItemKey
originalKey: ItemKey
phase: string
item: any
props: object
destroyed?: boolean
}

interface DeletedItem extends Item {
left?: ItemKey
right?: ItemKey
}

/**
* This tries to put deleted items back into the given `out` list in correct
* order. Deleted items must have a `left` and `right` property with key of
* their sibling which is used to find the correct placement.
*/
export function reconcileDeleted(
deleted: DeletedItem[],
current: Item[]
): any[] {
// Copy as we will be mutating the arrays
deleted = [...deleted]
current = [...current]

// Used to detect deadlock (when a pass finds 0 siblings)
let failedTries = 0

// Track where the current pass start/ends
let passIndex = 0
let nextPassIndex = deleted.length

// Insert all deleted items into `current`
for (let i = 0; i < deleted.length; i++) {
if (i === nextPassIndex) {
// Sanity test: Push to end if somehow no siblings were found
if (passIndex + failedTries === nextPassIndex) {
for (let j = i; j < deleted.length; j++) {
const { left, right, ...deletedItem } = deleted[j]
current.push(deletedItem)
}
break
}
// Update local state at the end of each pass
passIndex = nextPassIndex
nextPassIndex = deleted.length
failedTries = 0
}

// The index of the deleted item in `current`
let index = -1

// Look for the left or right sibling in `current`
const { left, right, ...deletedItem } = deleted[i]
for (let j = current.length; --j >= 0; ) {
const { originalKey: key } = current[j]
if (key === right) {
index = j
break
}
if (key === left) {
index = j + 1
break
}
}

// Items with no index are revisited in the next pass
if (index < 0) {
failedTries++
deleted.push(deleted[i])
} else {
current.splice(index, 0, deletedItem)
}
}

return current
}

export function freeze<T extends object>(obj: T): T {
if (
typeof process !== 'undefined' &&
Expand Down
13 changes: 2 additions & 11 deletions packages/core/src/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ export function Trail({ items, children, ...props }) {
})
}

export function Transition({ items, keys = null, children, ...props }) {
const transitions = useTransition(items, keys, props)
return transitions.map(({ item, key, props, phase }, index) => {
const result = children(item, phase, index)
const element = is.fun(result) ? result(props) : result
return element && element.type ? (
<element.type {...element.props} key={key} ref={element.ref} />
) : (
element
)
})
export function Transition({ items, children, ...props }) {
return useTransition(items, props)(children)
}
124 changes: 0 additions & 124 deletions packages/core/src/useTransition.d.ts

This file was deleted.

Loading