Skip to content
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

Hooks 🎣 #1220

Merged
merged 120 commits into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
b866832
placeholder
alexreardon Mar 14, 2019
f47daa5
using memo
alexreardon Mar 14, 2019
bd62767
animate in out
alexreardon Mar 14, 2019
9958d32
wip
alexreardon Mar 14, 2019
bb7795a
Droppable
alexreardon Mar 15, 2019
3b09df5
droppable dimension publisher
alexreardon Mar 15, 2019
cb1f717
working on drag drop context
alexreardon Mar 15, 2019
0feeee2
style marshal
alexreardon Mar 15, 2019
a004b6e
adding style marshal
alexreardon Mar 15, 2019
c7b09dc
more drag drop context
alexreardon Mar 15, 2019
e6af834
wip
alexreardon Mar 15, 2019
283f55a
draggable wip
alexreardon Mar 15, 2019
b9b4358
useConstant
alexreardon Mar 17, 2019
fa5ff4c
use constant in the house
alexreardon Mar 17, 2019
b8d9627
cleanup. moving to newer react-redux
alexreardon Mar 17, 2019
b4748d5
draggable
alexreardon Mar 17, 2019
da6fa5e
useConstant cleanup
alexreardon Mar 17, 2019
ef76da6
drag handle starting
alexreardon Mar 17, 2019
83ca8a1
figuring out drag handles
alexreardon Mar 18, 2019
1313ff3
wip
alexreardon Mar 18, 2019
00656f0
early signal for size
alexreardon Mar 18, 2019
2e3bdfd
yolo
alexreardon Mar 18, 2019
7b9e2fd
constant down
alexreardon Mar 18, 2019
0d771e5
sprinkling love
alexreardon Mar 18, 2019
dd72662
drag drop context
alexreardon Mar 18, 2019
c09f29d
going hooks all the way down
alexreardon Mar 18, 2019
379addf
validation for droppable
alexreardon Mar 18, 2019
437ac05
removing some logging
alexreardon Mar 18, 2019
96a1792
aborting drags
alexreardon Mar 18, 2019
7597757
more comments
alexreardon Mar 18, 2019
bb0060c
wip
alexreardon Mar 19, 2019
b0a94e2
for show
alexreardon Mar 19, 2019
697aae9
moving back to stable react-redux
alexreardon Mar 19, 2019
9853c12
wip
alexreardon Mar 19, 2019
93b64de
fixing flow
alexreardon Mar 19, 2019
a7fb2c1
correctly handling unmounting from mouse sensor
alexreardon Mar 19, 2019
f9915db
removing debug statement
alexreardon Mar 19, 2019
4eabc0b
use keyboard sensor
alexreardon Mar 19, 2019
70342a7
keyboard sensor
alexreardon Mar 19, 2019
0edd918
touch sensor
alexreardon Mar 19, 2019
bdb046c
linking in touch handle
alexreardon Mar 19, 2019
62c3f6c
removing unused things
alexreardon Mar 19, 2019
c31e946
wip
alexreardon Mar 19, 2019
6805ee0
fixing flow errors
alexreardon Mar 20, 2019
41f33d1
trying to write some tests
alexreardon Mar 20, 2019
e97f278
creating custom memo functions
alexreardon Mar 20, 2019
6203624
Merge remote-tracking branch 'origin/master' into hooks
alexreardon Mar 21, 2019
4747abf
adding goodness
alexreardon Mar 21, 2019
cadebc5
fixing import
alexreardon Mar 21, 2019
fbcef22
redux v7
alexreardon Mar 22, 2019
6b53bda
Merge branch 'master' of github.com:atlassian/react-beautiful-dnd int…
alexreardon Mar 22, 2019
7fb9498
bumping deps. using snapshot
alexreardon Mar 22, 2019
3c19b94
getting mouse sensors tests mostly working
alexreardon Mar 24, 2019
4aa5a75
mouse sensor tests passing
alexreardon Mar 24, 2019
85ceb1b
fixing tests. improving drag handle
alexreardon Mar 24, 2019
afbd2bd
more drag handle tests
alexreardon Mar 24, 2019
10c7540
tests for integration
alexreardon Mar 25, 2019
dab4354
naming improvement
alexreardon Mar 25, 2019
5288314
tests for controls
alexreardon Mar 25, 2019
4eec4ff
tests for drag handles
alexreardon Mar 25, 2019
7e387c8
more drag handle work
alexreardon Mar 25, 2019
e74b544
drag handle tests done except for focus management
alexreardon Mar 25, 2019
18370eb
tests for draggable dimension publisher
alexreardon Mar 25, 2019
5ea6c1e
tests for droppable
alexreardon Mar 25, 2019
dfa0f84
announcer tests
alexreardon Mar 26, 2019
2da4129
assorted tests
alexreardon Mar 26, 2019
0053f96
tests for drag-drop-context
alexreardon Mar 26, 2019
076734a
wip
alexreardon Mar 26, 2019
187f88c
wip
alexreardon Mar 26, 2019
96760e0
wip
alexreardon Mar 26, 2019
817d442
going back to getDerrivedStateFromProps
alexreardon Mar 26, 2019
fe0be1f
correctly aborting mouse-sensor
alexreardon Mar 26, 2019
8be2863
moving old animate-in-out tests back
alexreardon Mar 26, 2019
c192147
adding fix for aborted drags
alexreardon Mar 26, 2019
64cdd2b
adjusting placeholder tests for mount timer
alexreardon Mar 26, 2019
a0a5684
resolving conflict with master
alexreardon Mar 27, 2019
a4bcb54
toggling is enabled for droppable
alexreardon Mar 27, 2019
4eee1e3
create ref
alexreardon Mar 27, 2019
703303d
adding missing import
alexreardon Mar 27, 2019
a559519
starting to fix droppable dimension tests
alexreardon Mar 27, 2019
bd50540
handling updates for use-draggable-dimension-publisher
alexreardon Mar 27, 2019
711a4c2
fixing droppable tests
alexreardon Mar 27, 2019
e557764
test push forward
alexreardon Mar 27, 2019
4541937
refactoring error boundary
alexreardon Mar 27, 2019
14357d5
publishing tests
alexreardon Mar 28, 2019
abf5c21
scrollable droppable tests
alexreardon Mar 28, 2019
2668253
is enabled change test
alexreardon Mar 28, 2019
cf45963
droppable tests
alexreardon Mar 28, 2019
a076db0
droppable recollection tests
alexreardon Mar 28, 2019
296c4ec
draggable child render behaviour
alexreardon Mar 28, 2019
4d6784b
connected droppable child render behaviour
alexreardon Mar 28, 2019
a233fc0
more tests
alexreardon Mar 28, 2019
a37b858
adding action payload to logging
alexreardon Mar 28, 2019
225c814
fixing flow
alexreardon Mar 28, 2019
639c4f6
focus management
alexreardon Mar 29, 2019
dcf8ac0
fixing rollup
alexreardon Mar 29, 2019
5938f16
adding ssr console test
alexreardon Mar 29, 2019
8e9e6ae
useIsomorphicLayoutEffect
alexreardon Mar 29, 2019
a4c7d70
updating comment
alexreardon Mar 31, 2019
c40adab
updating snapshot and type
alexreardon Mar 31, 2019
47f7840
changing order in use-memo-one
alexreardon Mar 31, 2019
adbd7c8
fixing brwoser test
alexreardon Mar 31, 2019
d51f969
trying to again fix browser tests
alexreardon Mar 31, 2019
3d77a43
fixing tests
alexreardon Apr 1, 2019
972669d
removing unused files
alexreardon Apr 1, 2019
1bb8eaa
pointing tests and the right file
alexreardon Apr 1, 2019
6152b4b
removing redundant style
alexreardon Apr 1, 2019
7b2b2d8
safer guarding
alexreardon Apr 1, 2019
14862d9
trying to be concurrent mode safe
alexreardon Apr 1, 2019
864b372
useCallbackOne now using useMemoOne
alexreardon Apr 1, 2019
fa4fc56
moving to useMemoOne
alexreardon Apr 1, 2019
7d4f788
adding tests for use-memo-one
alexreardon Apr 1, 2019
4f7893a
shaving a few bytes
alexreardon Apr 1, 2019
8fc21f2
moving to use-memo-one
alexreardon Apr 2, 2019
539dcf1
adding array guards
alexreardon Apr 2, 2019
424abf3
bumping use-memo-one
alexreardon Apr 2, 2019
c41e1b3
bumping use-memo-one
alexreardon Apr 2, 2019
c5f5d6e
updating bundle size
alexreardon Apr 2, 2019
c278db0
moving to 1.0 of useMemoOne
alexreardon Apr 2, 2019
0fc6aa4
v11.0.0-beta
alexreardon Apr 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
14 changes: 14 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ module.exports = {
},
],

'no-restricted-imports': [
'error',
{
paths: [
{
name: 'react',
importNames: ['useMemo', 'useCallback'],
message:
'useMemo and useCallback are subject to cache busting. Please use useMemoOne and useCallbackOne',
},
],
},
],

// Allowing jsx in files with any file extension (old components have jsx but not the extension)
'react/jsx-filename-extension': 'off',

Expand Down
24 changes: 12 additions & 12 deletions .size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"dist/react-beautiful-dnd.js": {
"bundled": 357308,
"minified": 138768,
"gzipped": 40712
"bundled": 392153,
"minified": 146738,
"gzipped": 41191
},
"dist/react-beautiful-dnd.min.js": {
"bundled": 303784,
"minified": 113686,
"gzipped": 32910
"bundled": 324706,
"minified": 116369,
"gzipped": 33451
},
"dist/react-beautiful-dnd.esm.js": {
"bundled": 237952,
"minified": 125718,
"gzipped": 31356,
"bundled": 237886,
"minified": 123357,
"gzipped": 31310,
"treeshaked": {
"rollup": {
"code": 85891,
"import_statements": 832
"code": 30267,
"import_statements": 799
},
"webpack": {
"code": 88596
"code": 34399
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/move-between-lists.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as keyCodes from '../../src/view/key-codes';
import { timings } from '../../src/animation';

beforeEach(() => {
cy.visit('/iframe.html?selectedKind=board&selectedStory=simple');
cy.visit('/iframe.html?id=board--simple');
});

it('should move between lists', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/reorder-lists.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as keyCodes from '../../src/view/key-codes';
import { timings } from '../../src/animation';

beforeEach(() => {
cy.visit('/iframe.html?selectedKind=board&selectedStory=simple');
cy.visit('/iframe.html?id=board--simple');
});

it('should reorder lists', () => {
Expand Down
4 changes: 1 addition & 3 deletions cypress/integration/reorder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import * as keyCodes from '../../src/view/key-codes';
import { timings } from '../../src/animation';

beforeEach(() => {
cy.visit(
'/iframe.html?selectedKind=single%20vertical%20list&selectedStory=basic',
);
cy.visit('/iframe.html?id=single-vertical-list--basic');
});

it('should reorder a list', () => {
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ module.exports = {
'jest-watch-typeahead/filename',
'jest-watch-typeahead/testname',
],
verbose: true,
};
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-beautiful-dnd",
"version": "10.1.1",
"version": "11.0.0-beta",
"description": "Beautiful and accessible drag and drop for lists with React",
"author": "Alex Reardon <areardon@atlassian.com>",
"keywords": [
Expand Down Expand Up @@ -57,11 +57,11 @@
"@babel/runtime-corejs2": "^7.4.2",
"css-box-model": "^1.1.1",
"memoize-one": "^5.0.1",
"prop-types": "^15.6.1",
"raf-schd": "^4.0.0",
"react-redux": "^5.0.7",
"react-redux": "7.0.0-beta.0",
"redux": "^4.0.1",
"tiny-invariant": "^1.0.4"
"tiny-invariant": "^1.0.4",
"use-memo-one": "^1.0.0"
},
"devDependencies": {
"@atlaskit/css-reset": "^3.0.6",
Expand Down Expand Up @@ -134,7 +134,7 @@
"webpack": "^4.29.6"
},
"peerDependencies": {
"react": "^16.3.1"
"react": "^16.8.0"
},
"license": "Apache-2.0",
"jest-junit": {
Expand Down
15 changes: 9 additions & 6 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ const snapshotArgs =

const commonjsArgs = {
include: 'node_modules/**',
// needed for react-is via react-redux v5.1
// needed for react-is via react-redux
// https://stackoverflow.com/questions/50080893/rollup-error-isvalidelementtype-is-not-exported-by-node-modules-react-is-inde/50098540
namedExports: {
'node_modules/react-is/index.js': ['isValidElementType'],
'node_modules/react-redux/node_modules/react-is/index.js': [
'isValidElementType',
'isContextConsumer',
],
},
};

Expand All @@ -50,10 +53,10 @@ export default [
file: 'dist/react-beautiful-dnd.js',
format: 'umd',
name: 'ReactBeautifulDnd',
globals: { react: 'React' },
globals: { react: 'React', 'react-dom': 'ReactDOM' },
},
// Only deep dependency required is React
external: ['react'],
external: ['react', 'react-dom'],
plugins: [
json(),
babel(getBabelOptions({ useESModules: true })),
Expand All @@ -71,10 +74,10 @@ export default [
file: 'dist/react-beautiful-dnd.min.js',
format: 'umd',
name: 'ReactBeautifulDnd',
globals: { react: 'React' },
globals: { react: 'React', 'react-dom': 'ReactDOM' },
},
// Only deep dependency required is React
external: ['react'],
external: ['react', 'react-dom'],
plugins: [
json(),
babel(getBabelOptions({ useESModules: true })),
Expand Down
1 change: 1 addition & 0 deletions src/debug/middleware/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default (store: Store) => (next: Action => mixed) => (
action: Action,
): any => {
console.group(`action: ${action.type}`);
console.log('action payload', action.payload);
console.log('state before', store.getState());

const result: mixed = next(action);
Expand Down
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ export type {
OnDragEndResponder,
} from './types';

// Droppable
// Droppable types
export type {
Provided as DroppableProvided,
StateSnapshot as DroppableStateSnapshot,
DroppableProps,
} from './view/droppable/droppable-types';

// Draggable
// Draggable types
export type {
Provided as DraggableProvided,
StateSnapshot as DraggableStateSnapshot,
Expand All @@ -48,5 +48,5 @@ export type {
NotDraggingStyle,
} from './view/draggable/draggable-types';

// DragHandle
export type { DragHandleProps } from './view/drag-handle/drag-handle-types';
// DragHandle types
export type { DragHandleProps } from './view/use-drag-handle/drag-handle-types';
12 changes: 9 additions & 3 deletions src/state/action-creators.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,20 @@ export const moveLeft = (): MoveLeftAction => ({
payload: null,
});

type CleanActionArgs = {|
shouldFlush: boolean,
|};

type CleanAction = {|
type: 'CLEAN',
payload: null,
payload: CleanActionArgs,
|};

export const clean = (): CleanAction => ({
export const clean = (
args?: CleanActionArgs = { shouldFlush: false },
): CleanAction => ({
type: 'CLEAN',
payload: null,
payload: args,
});

export type AnimateDropArgs = {|
Expand Down
18 changes: 9 additions & 9 deletions src/state/create-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import dimensionMarshalStopper from './middleware/dimension-marshal-stopper';
import autoScroll from './middleware/auto-scroll';
import pendingDrop from './middleware/pending-drop';
import type { DimensionMarshal } from './dimension-marshal/dimension-marshal-types';
import type { StyleMarshal } from '../view/style-marshal/style-marshal-types';
import type { StyleMarshal } from '../view/use-style-marshal/style-marshal-types';
import type { AutoScroller } from './auto-scroller/auto-scroller-types';
import type { Responders, Announce } from '../types';
import type { Store } from './store-types';
Expand All @@ -27,19 +27,19 @@ const composeEnhancers =
: compose;

type Args = {|
getDimensionMarshal: () => DimensionMarshal,
dimensionMarshal: DimensionMarshal,
styleMarshal: StyleMarshal,
getResponders: () => Responders,
announce: Announce,
getScroller: () => AutoScroller,
autoScroller: AutoScroller,
|};

export default ({
getDimensionMarshal,
dimensionMarshal,
styleMarshal,
getResponders,
announce,
getScroller,
autoScroller,
}: Args): Store =>
createStore(
reducer,
Expand All @@ -50,7 +50,7 @@ export default ({
// > uncomment to use
// debugging logger
// require('../debug/middleware/log').default,
// user timing api
// // user timing api
// require('../debug/middleware/user-timing').default,
// debugging timer
// require('../debug/middleware/action-timing').default,
Expand All @@ -71,14 +71,14 @@ export default ({
// when moving into a phase where collection is no longer needed.
// We need to stop the marshal before responders fire as responders can cause
// dimension registration changes in response to reordering
dimensionMarshalStopper(getDimensionMarshal),
dimensionMarshalStopper(dimensionMarshal),
// Fire application responders in response to drag changes
lift(getDimensionMarshal),
lift(dimensionMarshal),
drop,
// When a drop animation finishes - fire a drop complete
dropAnimationFinish,
pendingDrop,
autoScroll(getScroller),
autoScroll(autoScroller),
// Fire responders for consumers (after update to store)
responders(getResponders, announce),
),
Expand Down
5 changes: 0 additions & 5 deletions src/state/dimension-marshal/dimension-marshal-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ export type DimensionMarshal = {|
descriptor: DroppableDescriptor,
callbacks: DroppableCallbacks,
) => void,
updateDroppable: (
previous: DroppableDescriptor,
descriptor: DroppableDescriptor,
callbacks: DroppableCallbacks,
) => void,
// it is possible for a droppable to change whether it is enabled during a drag
updateDroppableIsEnabled: (id: DroppableId, isEnabled: boolean) => void,
// it is also possible to update whether combining is enabled
Expand Down
26 changes: 0 additions & 26 deletions src/state/dimension-marshal/dimension-marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,31 +164,6 @@ export default (callbacks: Callbacks) => {
invariant(!collection, 'Cannot add a Droppable during a drag');
};

const updateDroppable = (
previous: DroppableDescriptor,
descriptor: DroppableDescriptor,
droppableCallbacks: DroppableCallbacks,
) => {
invariant(
entries.droppables[previous.id],
'Cannot update droppable registration as no previous registration was found',
);

// The id might have changed, so we are removing the old entry
delete entries.droppables[previous.id];

const entry: DroppableEntry = {
descriptor,
callbacks: droppableCallbacks,
};
entries.droppables[descriptor.id] = entry;

invariant(
!collection,
'You are not able to update the id or type of a droppable during a drag',
);
};

const unregisterDroppable = (descriptor: DroppableDescriptor) => {
const entry: ?DroppableEntry = entries.droppables[descriptor.id];

Expand Down Expand Up @@ -328,7 +303,6 @@ export default (callbacks: Callbacks) => {
updateDraggable,
unregisterDraggable,
registerDroppable,
updateDroppable,
unregisterDroppable,

// droppable changes
Expand Down
14 changes: 7 additions & 7 deletions src/state/middleware/auto-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ const shouldEnd = (action: Action): boolean =>
const shouldCancelPending = (action: Action): boolean =>
action.type === 'COLLECTION_STARTING';

export default (getScroller: () => AutoScroller) => (
store: MiddlewareStore,
) => (next: Dispatch) => (action: Action): any => {
export default (autoScroller: AutoScroller) => (store: MiddlewareStore) => (
next: Dispatch,
) => (action: Action): any => {
if (shouldEnd(action)) {
getScroller().stop();
autoScroller.stop();
next(action);
return;
}

if (shouldCancelPending(action)) {
getScroller().cancelPending();
autoScroller.cancelPending();
next(action);
return;
}
Expand All @@ -35,12 +35,12 @@ export default (getScroller: () => AutoScroller) => (
state.phase === 'DRAGGING',
'Expected phase to be DRAGGING after INITIAL_PUBLISH',
);
getScroller().start(state);
autoScroller.start(state);
return;
}

// auto scroll happens in response to state changes
// releasing all actions to the reducer first
next(action);
getScroller().scroll(store.getState());
autoScroller.scroll(store.getState());
};
7 changes: 3 additions & 4 deletions src/state/middleware/dimension-marshal-stopper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import type { Action, Dispatch } from '../store-types';
import type { DimensionMarshal } from '../dimension-marshal/dimension-marshal-types';

export default (getMarshal: () => DimensionMarshal) => () => (
next: Dispatch,
) => (action: Action): any => {
export default (marshal: DimensionMarshal) => () => (next: Dispatch) => (
action: Action,
): any => {
// Not stopping a collection on a 'DROP' as we want a collection to continue
if (
// drag is finished
Expand All @@ -13,7 +13,6 @@ export default (getMarshal: () => DimensionMarshal) => () => (
// no longer accepting changes once the drop has started
action.type === 'DROP_ANIMATE'
) {
const marshal: DimensionMarshal = getMarshal();
marshal.stopPublishing();
}

Expand Down
Loading