| 8 | import isElementVisible from '../../utils/is-element-visible' |
| 9 | |
| 10 | export default function delegate( |
| 11 | event = { type: 'init' }, |
| 12 | elements = this.store.elements |
| 13 | ) { |
| 14 | raf(() => { |
| 15 | const stale = event.type === 'init' || event.type === 'resize' |
| 16 | |
| 17 | each(this.store.containers, container => { |
| 18 | if (stale) { |
| 19 | container.geometry = getGeometry.call(this, container, true) |
| 20 | } |
| 21 | const scroll = getScrolled.call(this, container) |
| 22 | if (container.scroll) { |
| 23 | container.direction = { |
| 24 | x: mathSign(scroll.left - container.scroll.left), |
| 25 | y: mathSign(scroll.top - container.scroll.top) |
| 26 | } |
| 27 | } |
| 28 | container.scroll = scroll |
| 29 | }) |
| 30 | |
| 31 | /** |
| 32 | * Due to how the sequencer is implemented, it’s |
| 33 | * important that we update the state of all |
| 34 | * elements, before any animation logic is |
| 35 | * evaluated (in the second loop below). |
| 36 | */ |
| 37 | each(elements, element => { |
| 38 | if (stale || element.geometry === undefined) { |
| 39 | element.geometry = getGeometry.call(this, element) |
| 40 | } |
| 41 | element.visible = isElementVisible.call(this, element) |
| 42 | }) |
| 43 | |
| 44 | each(elements, element => { |
| 45 | if (element.sequence) { |
| 46 | sequence.call(this, element) |
| 47 | } else { |
| 48 | animate.call(this, element) |
| 49 | } |
| 50 | }) |
| 51 | |
| 52 | this.pristine = false |
| 53 | }) |
| 54 | } |