Skip to content

Commit

Permalink
Merge pull request #11 from synyx/camera-init
Browse files Browse the repository at this point in the history
Initialize camera when a tale is loaded
  • Loading branch information
stwa authored Jun 30, 2020
2 parents fc92c71 + 0beeed8 commit 939be81
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions js/project.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { db, handler, connect, connector, withInputSignals } from "flyps";
import {
db,
handler,
connect,
connector,
trigger,
withInputSignals,
} from "flyps";

export function findTale([tales, slug]) {
return tales.find(tale => tale.slug === slug);
Expand All @@ -8,7 +15,7 @@ connector(
"tales",
withInputSignals(
() => db,
db => db.tales,
db => db.tales || [],
),
);

Expand All @@ -25,6 +32,9 @@ connector(
withInputSignals(() => [connect("tales"), connect("tale-slug")], findTale),
);

// triggers an event whenever the tale changes
connect("tale").connect(tale => trigger("project/loaded", tale.value()));

handler("projects/get-all", () => ({
xhr: {
url: "/api/tales/",
Expand Down Expand Up @@ -95,3 +105,15 @@ handler("projects/request-error", response => {
handler("projects/activate", ({ db }, eventId, slug) => ({
db: { ...db, activeTale: slug },
}));

handler("project/loaded", ({ db }, eventId, tale) => {
let effects = {
db: { ...db, editor: { ...db.editor, activeSlide: undefined } },
};
if (tale.dimensions) {
let { width, height } = tale.dimensions;
let rect = { x: 0, y: 0, width: width, height: height };
effects.trigger = ["camera/fit-rect", rect];
}
return effects;
});

0 comments on commit 939be81

Please sign in to comment.