Skip to content

Commit 74807fb

Browse files
committed
base boiler plate
0 parents  commit 74807fb

File tree

7 files changed

+442
-0
lines changed

7 files changed

+442
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
.vscode
3+
*.log
4+
dist/

package.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "@nodegui/react-nodegui",
3+
"version": "1.0.0",
4+
"description": "React Native for building cross platform desktop applications",
5+
"main": "dist/",
6+
"author": "Atul R <[email protected]>",
7+
"private": false,
8+
"license": "MIT",
9+
"scripts": {
10+
"build:lib": "tsc",
11+
"demo": "tsc && node ./dist/demo.js",
12+
"demo:watch": "tsc-watch --onSuccess \"npm run demo\""
13+
},
14+
"dependencies": {
15+
"react": "^16.8.6",
16+
"react-reconciler": "^0.20.4"
17+
},
18+
"devDependencies": {
19+
"@types/react-reconciler": "^0.18.0",
20+
"prettier": "^1.18.2",
21+
"tsc-watch": "^2.2.1",
22+
"typescript": "^3.5.2"
23+
}
24+
}

src/demo.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import ReactNodeGui from "./renderer";
2+
import React from "react";
3+
4+
class App extends React.Component {
5+
render() {
6+
return "Hello";
7+
}
8+
}
9+
//@ts-ignore
10+
global.win = { rootWin: true };
11+
//@ts-ignore
12+
const root = global.win;
13+
14+
ReactNodeGui.render(<App />, root, () => {
15+
console.log("rendered");
16+
});

src/reconciler/index.ts

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import Reconciler from "react-reconciler";
2+
3+
enum FiberType {
4+
Text,
5+
View,
6+
Button
7+
}
8+
9+
//@ts-ignore
10+
const HostConfig: Reconciler.HostConfig<
11+
FiberType,
12+
object,
13+
any,
14+
any,
15+
any,
16+
any,
17+
any,
18+
any,
19+
any,
20+
any,
21+
any,
22+
any
23+
> = {
24+
//TODO We will specify all required methods here
25+
now: Date.now,
26+
getRootHostContext: function(nextRootInstance: any) {
27+
console.log("Root node", nextRootInstance);
28+
let context = {
29+
// This can contain any data that you want to pass down to immediate child
30+
};
31+
return context;
32+
},
33+
getChildHostContext: function(parentContext, fiberType, rootInstance) {
34+
let context = {};
35+
return context;
36+
},
37+
shouldSetTextContent: function(type, nextProps) {
38+
console.log("shouldSetTextContent", type, nextProps);
39+
return false;
40+
},
41+
createTextInstance: function(...args: any[]) {
42+
console.log("createTextInstance", ...args);
43+
},
44+
createInstance: function(...args: any[]) {
45+
console.log("createInstance", ...args);
46+
},
47+
appendInitialChild: function(...args: any[]) {
48+
console.log("appendInitialChild", ...args);
49+
},
50+
finalizeInitialChildren: function(
51+
instance,
52+
type,
53+
newProps,
54+
rootContainerInstance,
55+
currentHostContext
56+
) {
57+
console.log(
58+
"finalizeInitialChildren",
59+
instance,
60+
type,
61+
newProps,
62+
rootContainerInstance,
63+
currentHostContext
64+
);
65+
return false;
66+
},
67+
prepareForCommit: function(...args: any[]) {
68+
console.log("prepareForCommit", ...args);
69+
},
70+
resetAfterCommit: function(...args: any[]) {
71+
console.log("resetAfterCommit", ...args);
72+
}
73+
};
74+
75+
export default Reconciler(HostConfig);

src/renderer/index.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import reconciler from "../reconciler";
2+
3+
const CustomRenderer = {
4+
render(element: React.ReactNode, renderDom: any, callback: () => void) {
5+
// element: This is the react element for App component
6+
// renderDom: This is the host root element to which the rendered app will be attached.
7+
// callback: if specified will be called after render is done.
8+
9+
const isAsync = false; // Disables async rendering
10+
const container = reconciler.createContainer(renderDom, isAsync, false); // Creates root fiber node.
11+
12+
const parentComponent = null; // Since there is no parent (since this is the root fiber). We set parentComponent to null.
13+
reconciler.updateContainer(element, container, parentComponent, callback); // Start reconcilation and render the result
14+
}
15+
};
16+
17+
export default CustomRenderer;

tsconfig.json

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"compilerOptions": {
3+
/* Basic Options */
4+
"target": "ES2015" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
5+
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
6+
// "lib": [], /* Specify library files to be included in the compilation. */
7+
// "allowJs": true /* Allow javascript files to be compiled. */,
8+
// "checkJs": true, /* Report errors in .js files. */
9+
"jsx": "react" /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */,
10+
"declaration": true /* Generates corresponding '.d.ts' file. */,
11+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
12+
"sourceMap": true /* Generates corresponding '.map' file. */,
13+
// "outFile": "./", /* Concatenate and emit output to single file. */
14+
"outDir": "./dist" /* Redirect output structure to the directory. */,
15+
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
16+
// "composite": true, /* Enable project compilation */
17+
// "incremental": true, /* Enable incremental compilation */
18+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
19+
// "removeComments": true, /* Do not emit comments to output. */
20+
// "noEmit": true, /* Do not emit outputs. */
21+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
22+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
23+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
24+
25+
/* Strict Type-Checking Options */
26+
"strict": true /* Enable all strict type-checking options. */,
27+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
28+
// "strictNullChecks": true, /* Enable strict null checks. */
29+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
30+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
31+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
32+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
33+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
34+
35+
/* Additional Checks */
36+
// "noUnusedLocals": true, /* Report errors on unused locals. */
37+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
38+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
39+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
40+
41+
/* Module Resolution Options */
42+
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
43+
// "baseUrl": "./" /* Base directory to resolve non-absolute module names. */,
44+
// "paths": {} /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */,
45+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
46+
// "typeRoots": [], /* List of folders to include type definitions from. */
47+
// "types": [] /* Type declaration files to be included in compilation. */,
48+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
49+
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
50+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
51+
52+
/* Source Map Options */
53+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
54+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
55+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
56+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
57+
58+
/* Experimental Options */
59+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
60+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
61+
"resolveJsonModule": true
62+
},
63+
"include": ["."]
64+
}

0 commit comments

Comments
 (0)