Skip to content

Commit

Permalink
registerType => register
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Feb 17, 2015
1 parent 4ffa1a6 commit 3435419
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 34 deletions.
30 changes: 15 additions & 15 deletions README.md
Expand Up @@ -105,11 +105,11 @@ var Image = React.createClass({
mixins: [DragDropMixin],

statics: {
configureDragDrop(registerType) {
configureDragDrop(register) {

// Specify all supported types by calling registerType(type, { dragSource?, dropTarget? })
// Specify all supported types by calling register(type, { dragSource?, dropTarget? })

registerType(ItemTypes.IMAGE, {
register(ItemTypes.IMAGE, {

// dragSource, when specified, is {
// beginDrag(component),
Expand Down Expand Up @@ -151,15 +151,15 @@ var Image = React.createClass({
By specifying `configureDragDrop` in `statics`, we tell `DragDropMixin` the drag-drop behavior of this component. Both draggable and droppable components use the same mixin.
Inside `configureDragDrop`, we need to call `registerType` for each of our custom `ItemTypes` that component supports. For example, there might be several representations of images in your app, and each would provide a `dragSource` for `ItemTypes.IMAGE`.
Inside `configureDragDrop`, we need to call `register` for each of our custom `ItemTypes` that component supports. For example, there might be several representations of images in your app, and each would provide a `dragSource` for `ItemTypes.IMAGE`.
A `dragSource` is just an object specifying how the drag source works. You must implement `beginDrag(component)` to return `item` that represents the data you're dragging and, optionally, a few options that adjust the dragging UI. You can optionally `canDrag(component)` to forbid dragging, or `endDrag(component, dropEffect)` to execute some logic when the drop has (or has not) occured. And you can share this logic between components by letting a shared mixins generate `dragSource` for them.
Finally, you must use `{...this.dragSourceFor(itemType)}` on some (one or more) elements in `render` to attach drag handlers. This means you can have several “drag handles” in one element, and they may even correspond to different item types. (If you're not familiar with [JSX Spread Attributes syntax](https://gist.github.com/sebmarkbage/07bbe37bc42b6d4aef81), check it out).
### Simple Drop Target
Let's say we want `ImageBlock` to be a drop target for `IMAGE`s. It's pretty much the same, except that we need to give `registerType` a `dropTarget` implementation:
Let's say we want `ImageBlock` to be a drop target for `IMAGE`s. It's pretty much the same, except that we need to give `register` a `dropTarget` implementation:
```javascript
var { DragDropMixin } = require('react-dnd'),
Expand All @@ -169,8 +169,8 @@ var ImageBlock = React.createClass({
mixins: [DragDropMixin],

statics: {
configureDragDrop(registerType) {
registerType(ItemTypes.IMAGE, {
configureDragDrop(register) {
register(ItemTypes.IMAGE, {

// dropTarget, when specified, is {
// acceptDrop(component, item)?,
Expand Down Expand Up @@ -218,8 +218,8 @@ var ImageBlock = React.createClass({
mixins: [DragDropMixin],

statics: {
configureDragDrop(registerType) {
registerType(ItemTypes.IMAGE, {
configureDragDrop(register) {
register(ItemTypes.IMAGE, {

// Add a drag source that only works when ImageBlock has an image:

Expand Down Expand Up @@ -272,8 +272,8 @@ var ImageUploader = React.createClass({
mixins: [DragDropMixin],

statics: {
configureDragDrop(registerType) {
registerType(NativeDragItemTypes.FILE, {
configureDragDrop(register) {
register(NativeDragItemTypes.FILE, {
dropTarget: {
acceptDrop(component, item) {
// Do something with files
Expand Down Expand Up @@ -317,12 +317,12 @@ I have not covered everything but it's possible to use this API in a few more wa
### `require('react-dnd').DragDropMixin`
`statics.configureDragDrop(registerType)`
`statics.configureDragDrop(register)`
Gives you a chance to configure drag and drop on your component.
Components with `DragDropMixin` will have this method.
`registerType(type, { dragSource?, dropTarget? })`
`register(type, { dragSource?, dropTarget? })`
Call this method to specify component behavior as drag source or drop target for given type.
This method is passed as a parameter to `configureDragDrop`.
Expand Down Expand Up @@ -394,8 +394,8 @@ getImageUrlsToPreload() {

// You can now use `this.hasPreloadedImage(url)` and `this.getPreloadedImage(url)` in your `dragSource`:
statics: {
configureDragDrop(registerType) {
registerType(ItemTypes.MY_ITEM, {
configureDragDrop(register) {
register(ItemTypes.MY_ITEM, {
dragSource: {
canDrag(component) {
return component.hasPreloadedImage('some-img-url1');
Expand Down
4 changes: 2 additions & 2 deletions examples/_drag-around-custom/Container.js
Expand Up @@ -34,8 +34,8 @@ var Container = React.createClass({
},

statics: {
configureDragDrop(registerHandler, context) {
registerHandler(ItemTypes.BOX, {
configureDragDrop(register, context) {
register(ItemTypes.BOX, {
dropTarget: {
acceptDrop(component, item, e) {
var delta = context.getCurrentOffsetDelta(),
Expand Down
4 changes: 2 additions & 2 deletions examples/_drag-around-custom/DraggableBox.js
Expand Up @@ -31,8 +31,8 @@ var DraggableBox = React.createClass({
},

statics: {
configureDragDrop(registerType) {
registerType(ItemTypes.BOX, {
configureDragDrop(register) {
register(ItemTypes.BOX, {
dragSource: {
beginDrag(component, e) {
return {
Expand Down
4 changes: 2 additions & 2 deletions examples/_drag-around-naive/Box.js
Expand Up @@ -16,8 +16,8 @@ var Box = React.createClass({
},

statics: {
configureDragDrop(registerType) {
registerType(ItemTypes.BOX, {
configureDragDrop(register) {
register(ItemTypes.BOX, {
dragSource: {
beginDrag(component, e) {
return {
Expand Down
4 changes: 2 additions & 2 deletions examples/_drag-around-naive/Container.js
Expand Up @@ -24,8 +24,8 @@ var Container = React.createClass({
},

statics: {
configureDragDrop(registerType) {
registerType(ItemTypes.BOX, {
configureDragDrop(register) {
register(ItemTypes.BOX, {
dropTarget: {
acceptDrop(component, item, e) {
var left = Math.round(item.startLeft + (e.pageX - item.startPageX)),
Expand Down
4 changes: 2 additions & 2 deletions examples/_dustbin-interesting/makeDustbin.js
Expand Up @@ -16,7 +16,7 @@ function makeDustbin(accepts) {
},

statics: {
configureDragDrop(registerType) {
configureDragDrop(register) {
var dropTarget = {
acceptDrop(component, item) {
component.setState({
Expand All @@ -26,7 +26,7 @@ function makeDustbin(accepts) {
};

accepts.forEach(itemType => {
registerType(itemType, {
register(itemType, {
dropTarget: dropTarget
});
});
Expand Down
4 changes: 2 additions & 2 deletions examples/_dustbin-interesting/makeItem.js
Expand Up @@ -20,8 +20,8 @@ function makeItem(dropType) {
},

statics: {
configureDragDrop(registerType) {
registerType(dropType, {
configureDragDrop(register) {
register(dropType, {
dragSource: {
beginDrag(component) {
return {
Expand Down
4 changes: 2 additions & 2 deletions examples/_dustbin-simple/Dustbin.js
Expand Up @@ -8,8 +8,8 @@ var Dustbin = React.createClass({
mixins: [DragDropMixin],

statics: {
configureDragDrop(registerType) {
registerType(ItemTypes.ITEM, {
configureDragDrop(register) {
register(ItemTypes.ITEM, {
dropTarget: {
acceptDrop(component, item) {
window.alert('You dropped ' + item.name + '!');
Expand Down
4 changes: 2 additions & 2 deletions examples/_dustbin-simple/Item.js
Expand Up @@ -13,8 +13,8 @@ var Item = React.createClass({
},

statics: {
configureDragDrop(registerType) {
registerType(ItemTypes.ITEM, {
configureDragDrop(register) {
register(ItemTypes.ITEM, {
dragSource: {
beginDrag(component) {
return {
Expand Down
4 changes: 2 additions & 2 deletions examples/_sortable-simple/Card.js
Expand Up @@ -15,8 +15,8 @@ var Card = React.createClass({
},

statics: {
configureDragDrop(registerType) {
registerType(ItemTypes.CARD, {
configureDragDrop(register) {
register(ItemTypes.CARD, {
dragSource: {
beginDrag(component) {
return {
Expand Down
2 changes: 1 addition & 1 deletion modules/utils/createDragDropMixin.js
Expand Up @@ -160,7 +160,7 @@ function createDragDropMixin(backend) {
} else {
invariant(
this.constructor.configureDragDrop,
'%s must implement static configureDragDrop(registerType) to use DragDropMixin',
'%s must implement static configureDragDrop(register, context) to use DragDropMixin',
this.constructor.displayName
);
}
Expand Down

0 comments on commit 3435419

Please sign in to comment.