├── .gitignore
├── Readme.md
├── docs
├── grid.gif
├── grid.mov
├── photojump.gif
└── photojump.mov
├── example.js
├── index.html
├── index.js
├── package.json
├── photojump.js
└── webpack.config.js
/.gitignore:
--------------------------------------------------------------------------------
1 | *.swp
2 |
3 | /node_modules
4 | /build
5 | *.swo
6 |
--------------------------------------------------------------------------------
/Readme.md:
--------------------------------------------------------------------------------
1 | # teleporter
2 |
3 | Teleport components around the tree without losing state or destroying the
4 | DOM!
5 |
6 | [some context/discussion in this gist](https://gist.github.com/chenglou/34b155691a6f58091953)
7 |
8 | ```javascript
9 | import {teleportable, teleparent} from 'react-teleport'
10 | ```
11 |
12 | ## Examples
13 |
14 | ### [Basic Grid](docs/grid.mov)
15 |
16 | [read the source](./example.js), interesing lines identified with `/***\ <---- \***/`
17 |
18 | (click image for .mov)
19 |
20 | [](docs/grid.mov)
21 |
22 | ### [Photo list](docs/photojump.mov)
23 |
24 | [read the source](./photojump.js), interesing lines identified with `/***\ <---- \***/`
25 |
26 | (click image for .mov)
27 |
28 | [](docs/photojump.mov)
29 |
30 | ## API
31 |
32 | ### `@teleportable`
33 |
34 | ```javascript
35 | /*
36 | * This function is best used as a decorator, and it makes a component "teleportable".
37 | *
38 | * A teleportable component can be moved between parents, nodes, etc. without
39 | * losing state, and without losing the DOM tree.
40 | *
41 | * Props:
42 | * - telekey: a teleport key. `teleparents` can create teleport keys.
43 | *
44 | * When the `teleparent` that created a telekey is garbage collected
45 | * (unmounted from the dom), then this teleportable component will also be
46 | * unmounted, but *not until then*.
47 | *
48 | * So if you have a long-lived teleparent with lots of teleportable children,
49 | * you could end up with a fair amount of garbage.
50 | */
51 | ```
52 |
53 | ### `@teleparent`
54 |
55 | ```javascript
56 | /**
57 | * Also a @decorator. Makes a component into a `teleparent`.
58 | *
59 | * Teleparents can create telekeys (the unique ids used to manage teleportable
60 | * components), via two functions, given as props:
61 | *
62 | * - makeTelekey() -> a new telekey
63 | * - getTelekey(id) -> get (or create if needed) the telekey corresponding to
64 | * some id
65 | *
66 | * If you only have one or two teleportable components, then `makeTelekey`
67 | * probably makes the most sense.
68 | *
69 | * If you have a bunch of components that need to be teleportable, that are
70 | * identified by some string id already, you can use `getTelekey(id)` to
71 | * always get the same `telekey` for a given `id`.
72 | *
73 | * See `photojump.js` for an example of using `getTelekey`, and `example.js`
74 | * for a simple example of using `makeTelekey`.
75 | */
76 | ```
77 |
78 |
--------------------------------------------------------------------------------
/docs/grid.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaredly/react-teleporter/8e395690c2758fcab4dc4d97787fdb7938cea542/docs/grid.gif
--------------------------------------------------------------------------------
/docs/grid.mov:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaredly/react-teleporter/8e395690c2758fcab4dc4d97787fdb7938cea542/docs/grid.mov
--------------------------------------------------------------------------------
/docs/photojump.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaredly/react-teleporter/8e395690c2758fcab4dc4d97787fdb7938cea542/docs/photojump.gif
--------------------------------------------------------------------------------
/docs/photojump.mov:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaredly/react-teleporter/8e395690c2758fcab4dc4d97787fdb7938cea542/docs/photojump.mov
--------------------------------------------------------------------------------
/example.js:
--------------------------------------------------------------------------------
1 |
2 | import React from 'react'
3 |
4 | import {teleportable, teleparent} from './'
5 |
6 | const ten = []
7 | for (let i=0; i<10; i++) ten.push(i)
8 |
9 | @teleportable /***\ <---- \***/
10 | class AwesomeItem extends React.Component {
11 | constructor(props) {
12 | super(props)
13 | this.state = {presses: 0}
14 | }
15 |
16 | componentDidMount() {
17 | console.log('Mouting!')
18 | }
19 |
20 | render() {
21 | return