live_motion icon indicating copy to clipboard operation
live_motion copied to clipboard

Adding to project, README instructions

Open brainlid opened this issue 3 years ago • 3 comments
trafficstars

I'm having trouble following the README to add this to a project.

Example:

import { createLiveMotion } from 'live_motion';
const { hook: motionHook, handleMotionUpdates } = createLiveMotion();

let Hooks = Object.assign({},
  SortableOption.hooks,
  Scrolling.hooks,
  AudioMp3.hooks,
  ...motionHook,
)

Errors on page load with JS console error: "Uncaught TypeError: Found non-callable @@iterator"

When I try expressing it more like how I expect it to be, it works.

let Hooks = Object.assign({},
  SortableOption.hooks,
  Scrolling.hooks,
  AudioMp3.hooks,
  motionHook
)

Just a simple update to README.md?

brainlid avatar Jul 26 '22 11:07 brainlid

That's because ...motionHook is the JavaScript spread operator (...). In your example, you are using the Object.assign() function, which expects an object. The spread operator will spread all it's object properties into the current object, where it is spread into.

So basically the following are equivalent.

const Hooks = {
  ...SortableOption.hooks,
  ...Scrolling.hooks,
  ...AudioMp3.hooks,
  ...motionHook
}

const Hooks = Object.assign({},
  SortableOption.hooks,
  Scrolling.hooks,
  AudioMp3.hooks,
  motionHook
)

We can clarify this in the README, I just assumed this was common knowledge. But I may be biased here, as I have a strong JS background.

benvp avatar Jul 26 '22 20:07 benvp

I used to have a strong JS knowledge... but I'm moving to heavily to LiveView because I don't want to maintain that up to date knowledge with JS. :slightly_smiling_face: Honestly, I've been trying to get out of JS-land for years. It feels like you have to run on a treadmill just to stay in place.

brainlid avatar Jul 26 '22 20:07 brainlid

Haha, yeah. JS moved at a slow pace before transpilers started to show up. And now the wheel get's reinvented like twice a day. 😛

benvp avatar Jul 26 '22 20:07 benvp