🍿 LiveMotion

LiveMotion enables high performance animations declared on the server and run on the client.

Features

Installation

LiveMotion makes use of Phoenix LiveView hooks and therefore the setup requires a few more steps than just adding the dependency to the Mixfile. However, the JS part is included and works without node installed.

Add the live_motion dependency to your mix.exs file.

def deps do
[
{:live_motion, "~> 0.1.0"}
]
end

Open up your app.js and import createLiveMotion and initialize LiveMotion.

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

Now in your hook definition, add the LiveMotion hook.

const hooks = {
// your other hooks
// ...
...motionHook,
};

Finally, we need to make sure that LiveView does not overwrite the style attributes generated by LiveMotion. In your LiveSocket initialization, add the following function into onBeforeElUpdated(from, to).

let liveSocket = new LiveSocket('/live', Socket, {
params: { _csrf_token: csrfToken },
hooks,
dom: {
onBeforeElUpdated(from, to) {
// add this line
handleMotionUpdates(from, to);
},
},
});

If you are using node and have npm or yarn installed, one additional step is required.

Show Instructions for npm / yarn

We need to add the JS part as a dependency to our package.json file. From the root directory of your project, run the following command.

If you are using npm:

npm install --prefix assets --save ../deps/live_motion

If you are using yarn:

yarn add --cwd assets file:../deps/live_motion

Roadmap

There are still a lot of things to do to get to a mature library.

Limitations

LiveMotion is still in the early days, so breaking changes are expected. Additionally, there are still a few limitations, which will be added in future releases.

Contributing

Any contribution is very much welcome. The project itself works just as any other mix project.

Please do not include an updated priv/static/live_view.js in pull requests. The maintainers will update it as part of the release process.