Skip to content

Commit

Permalink
found bug in diff. turning off for now. bump version to 0.2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
floodfx committed Mar 24, 2022
1 parent 4975afc commit 79d64b3
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 262 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ dist/
.parcel-cache/
.DS_Store
coverage/lcov-report/
coverage/lcov.info
coverage/lcov.info
diffs/
487 changes: 242 additions & 245 deletions coverage/clover.xml

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions coverage/coverage-final.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "liveviewjs",
"version": "0.2.5",
"version": "0.2.6",
"description": "LiveViewJS brings the power of LiveView to Typescript and Javascript developers and applications.",
"targets": {
"client": {
Expand Down
29 changes: 29 additions & 0 deletions src/server/live_view_server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { html, HtmlSafeString } from "./templates";

describe("test live view server", () => {
let lvServer: LiveViewServer;
let caughtError = jest.fn();

const liveViewRootTemplate = (session: SessionData, inner_content: HtmlSafeString) => html`<div>
${session.csrfToken} ${inner_content}
Expand All @@ -33,6 +34,11 @@ describe("test live view server", () => {
},
liveViewRootTemplate,
});
lvServer.expressApp.use((error: Error, req: Request, res: Response, next: NextFunction) => {
caughtError(error);
res.status(501).send("error");
next();
});
lvServer.start();
});
afterEach(() => {
Expand Down Expand Up @@ -288,6 +294,19 @@ describe("test live view server", () => {
done();
});
});

it("catches a throwing LiveView in HTTP", (done) => {
let lvComponent = new ThrowingLiveView();
lvServer.registerLiveViewRoute("/test", lvComponent);
request(lvServer.httpServer)
.get("/test")
.expect(501)
.then((res) => {
expect(caughtError).toHaveBeenCalled();
expect(res.text).toEqual("error");
done();
});
});
});

declare module "express-session" {
Expand Down Expand Up @@ -358,3 +377,13 @@ class TestRedirectingLiveView extends BaseLiveView<LiveViewContext, {}> {
return html`<div>never</div>`;
}
}

class ThrowingLiveView extends BaseLiveView<LiveViewContext, {}> {
mount(params: LiveViewMountParams, session: Partial<SessionData>, socket: LiveViewSocket<LiveViewContext>) {
throw new Error("test");
}

render(ctx: LiveViewContext): LiveViewTemplate {
return html`<div>never</div>`;
}
}
19 changes: 10 additions & 9 deletions src/server/socket/component_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,20 +307,21 @@ export class LiveViewComponentManager {
await this.liveView.handleEvent(event, value, this.socket);
}

// skip ctxEqual for now
const ctxEqual = areContextsValueEqual(previousContext, this.socket.context);
let diff: Parts = {};

// only calc diff if contexts have changed
if (!ctxEqual || event === "lv:clear-flash") {
// get old render tree and new render tree for diffing
const oldView = await this.liveView.render(previousContext, this.defaultLiveViewMeta());
let view = await this.liveView.render(this.socket.context, this.defaultLiveViewMeta());

// wrap in root template if there is one
view = await this.maybeWrapInRootTemplate(view);
// if (!ctxEqual || event === "lv:clear-flash") {
// get old render tree and new render tree for diffing
// const oldView = await this.liveView.render(previousContext, this.defaultLiveViewMeta());
let view = await this.liveView.render(this.socket.context, this.defaultLiveViewMeta());

diff = deepDiff(oldView.partsTree(), view.partsTree());
}
// wrap in root template if there is one
view = await this.maybeWrapInRootTemplate(view);
diff = view.partsTree();
// diff = deepDiff(oldView.partsTree(), view.partsTree());
// }

diff = this.maybeAddPageTitleToParts(diff);
diff = this.maybeAddEventsToParts(diff);
Expand Down

0 comments on commit 79d64b3

Please sign in to comment.