Commit 19f676a1 authored by Laurent Wouters's avatar Laurent Wouters
Browse files

Implementing fetchable views

parent 49b05b77be4f
......@@ -20,6 +20,20 @@
/// <reference path="./rdflib-interface.d.ts"/>
import { RdfStore } from "rdflib";
import { ReactNode } from "react";
/**
* A renderer for an application
*/
export interface ViewRenderer {
/**
* Renders a resource belonging to an RDF store
* @param store The RDF store holding the data to be rendered
* @param root The root resource
* @param target The target resource for this view
*/
render(store: RdfStore, root: string, target: string): ReactNode;
}
/**
* The public interface for the application
......@@ -30,7 +44,7 @@ export interface Application {
* @param content The content
* @param root The URI of the root resource
*/
onContent(content: RdfStore, root: string): void;
onContent(renderer: ViewRenderer, content: RdfStore, root: string): void;
/**
* Sets the application on error
......
......@@ -21,7 +21,7 @@
/// <reference path="./rdflib-interface.d.ts"/>
import { RdfStore } from "rdflib";
import { ReactNode } from "react";
import { Application } from "./application";
import { ViewRenderer, Application } from "./application";
/**
* The kind of locations for the location of a view definition
......@@ -388,7 +388,7 @@ export function resolveViewFor(
/**
* A renderer for an application
*/
export class ViewRenderer {
export class ViewRendererImpl implements ViewRenderer {
/**
* Initializes a renderer
* @param application The parent application
......@@ -397,7 +397,6 @@ export class ViewRenderer {
constructor(application: Application, registry: ViewRegistry) {
this.application = application;
this.registry = registry;
this.render = this.render.bind(this);
loadImplementations(registry);
}
......
......@@ -20,8 +20,7 @@
/// <reference path="../common/rdflib-interface.d.ts"/>
import { RdfStore } from "rdflib";
import { Application } from "../common/application";
import { ViewRenderer } from "../common/view-registry";
import { Application, ViewRenderer } from "../common/application";
import * as React from "react";
enum StateType {
......@@ -43,6 +42,7 @@ export class Viewer extends React.Component<any, State> implements Application {
content: null,
root: null
};
renderer: ViewRenderer = null;
constructor(props: any) {
super(props);
......@@ -55,7 +55,12 @@ export class Viewer extends React.Component<any, State> implements Application {
* @param content The content
* @param root The URI of the root resource
*/
public onContent(content: RdfStore, root: string): void {
public onContent(
renderer: ViewRenderer,
content: RdfStore,
root: string
): void {
this.renderer = renderer;
let newState: State = {
stateType: StateType.Displaying,
message: "",
......@@ -111,8 +116,11 @@ export class Viewer extends React.Component<any, State> implements Application {
</div>
);
} else if (this.state.stateType == StateType.Displaying) {
let renderer = new ViewRenderer(this, null);
let result = renderer.render(this.state.content, this.state.root);
let result = this.renderer.render(
this.state.content,
this.state.root,
this.state.root
);
if (result != null) return result;
return (
<div
......
......@@ -26,6 +26,7 @@ import { Viewer } from "./app-viewer";
import * as React from "react";
import * as ReactDOM from "react-dom";
import "chrome";
import { ViewRegistry, ViewRendererImpl } from "../common/view-registry";
/**
* The current application
......@@ -47,7 +48,17 @@ function onUpdateActivate(tabData: TabData): void {
injectApplication();
loadRdfStore(tabData)
.then((store: any) => {
currentApp.onContent(store, tabData.primaryTopic);
chrome.runtime.sendMessage(
{
requestType: "GetViewRegistry",
senderId: "content",
payload: null
},
(registry: ViewRegistry) => {
let renderer = new ViewRendererImpl(currentApp, registry);
currentApp.onContent(renderer, store, tabData.primaryTopic);
}
);
})
.catch(reason => {
currentApp.onError(reason.toString());
......@@ -136,7 +147,7 @@ function injectApplication() {
document.body.insertBefore(appContent, document.body.firstChild);
let viewer = <Viewer />;
let x = ReactDOM.render(viewer, document.getElementById(ID));
currentApp = x as Viewer;
currentApp = (x as Viewer) as Application;
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment