Skip to content

Commit fbcc015

Browse files
committed
🔥
0 parents  commit fbcc015

26 files changed

+5859
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/.idea/
2+
/node_modules/
3+
/yarn.lock
4+
/yarn-error.log

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
src
2+
tsconfig.json

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# VR
2+
Virtual DOM and Components.
3+
4+
## Installation
5+
NPM:
6+
```shell script
7+
npm install @telegramv/vr
8+
```
9+
10+
Yarn:
11+
```shell script
12+
yarn add @telegramv/vr
13+
```
14+
15+
## Usage
16+
Example:
17+
```jsx harmony
18+
import VRDOM from "@telegramv/vr/dom";
19+
import StatelessComponent from "@telegramv/vr/StatelessComponent";
20+
import StatefulComponent from "@telegramv/vr/StatefulComponent";
21+
22+
const Button = ({onClick}, content) => {
23+
return <button onClick={onClick}>content</button>
24+
}
25+
26+
class Title extends StatelessComponent {
27+
render(state, props) {
28+
return <h1>{props.value}</h1>
29+
}
30+
}
31+
32+
class Counter extends StatefulComponent {
33+
state = {
34+
count: 0
35+
}
36+
37+
render(state) {
38+
return (
39+
<div>
40+
<Title value={state.count}/>
41+
42+
<Button onClick={() => this.setState({
43+
count: this.state.count + 1
44+
})}>Increment</Button>
45+
</div>
46+
);
47+
}
48+
}
49+
50+
const $element = VRDOM.render(<Counter/>);
51+
console.log($element);
52+
```

jestconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"transform": {
3+
"^.+\\.(t|j)sx?$": "ts-jest"
4+
},
5+
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
6+
"moduleFileExtensions": [
7+
"ts",
8+
"tsx",
9+
"js",
10+
"jsx",
11+
"json",
12+
"node"
13+
]
14+
}

lib/StatefulComponent.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare class StatefulComponent {
2+
}
3+
export default StatefulComponent;

lib/StatefulComponent.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"use strict";
2+
/*
3+
* Telegram V
4+
* Copyright (C) 2020 Davyd Kohut
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
Object.defineProperty(exports, "__esModule", { value: true });
20+
class StatefulComponent {
21+
}
22+
exports.default = StatefulComponent;

lib/StatelessComponent.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare class StatelessComponent {
2+
}
3+
export default StatelessComponent;

lib/StatelessComponent.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"use strict";
2+
/*
3+
* Telegram V
4+
* Copyright (C) 2020 Davyd Kohut
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
Object.defineProperty(exports, "__esModule", { value: true });
20+
class StatelessComponent {
21+
}
22+
exports.default = StatelessComponent;

lib/dom/VRElement.d.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export declare type VRElementAttrs = null | any;
2+
export declare type VRElementListeners = {
3+
[key: string]: (event: Event) => any;
4+
} | null;
5+
export declare type VRNode = VRElement | any;
6+
export declare type VRElementChildren = Array<VRNode>;
7+
export declare type VRElementProps = {
8+
attributes: VRElementAttrs;
9+
listeners: VRElementListeners;
10+
children: VRElementChildren;
11+
};
12+
declare class VRElement {
13+
tagName: string;
14+
attributes: VRElementAttrs;
15+
listeners: VRElementListeners;
16+
children: VRElementChildren;
17+
constructor(tagName: string, props?: VRElementProps);
18+
}
19+
export default VRElement;

lib/dom/VRElement.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"use strict";
2+
/*
3+
* Telegram V
4+
* Copyright (C) 2020 Davyd Kohut
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
Object.defineProperty(exports, "__esModule", { value: true });
20+
class VRElement {
21+
constructor(tagName, props) {
22+
this.attributes = null;
23+
this.listeners = null;
24+
this.children = [];
25+
this.tagName = tagName;
26+
if (props) {
27+
this.attributes = props.attributes;
28+
this.listeners = props.listeners;
29+
this.children = props.children;
30+
}
31+
}
32+
}
33+
exports.default = VRElement;

lib/dom/createElement.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import VRElement, { VRElementChildren } from "./VRElement";
2+
declare const createElement: (tagName: string, attrs?: any, ...children: VRElementChildren) => VRElement;
3+
export default createElement;

lib/dom/createElement.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"use strict";
2+
/*
3+
* Telegram V
4+
* Copyright (C) 2020 Davyd Kohut
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
var __importDefault = (this && this.__importDefault) || function (mod) {
20+
return (mod && mod.__esModule) ? mod : { "default": mod };
21+
};
22+
Object.defineProperty(exports, "__esModule", { value: true });
23+
const VRElement_1 = __importDefault(require("./VRElement"));
24+
const index_1 = __importDefault(require("./index"));
25+
const createElement = (tagName, attrs = null, ...children) => {
26+
if (tagName === index_1.default.Fragment) {
27+
console.warn("Fragments are not fully supported.");
28+
}
29+
const attributes = {};
30+
const listeners = {};
31+
if (attrs) {
32+
// @ts-ignore
33+
for (const [k, v] of Object.entries(attrs)) {
34+
if (k.startsWith("on")) {
35+
listeners[k.substring(2).toLowerCase()] = v;
36+
}
37+
else {
38+
attributes[k] = v;
39+
}
40+
}
41+
}
42+
return new VRElement_1.default(tagName, { attributes, listeners, children });
43+
};
44+
exports.default = createElement;

lib/dom/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare const VRDOM: {
2+
createElement: (tagName: string, attrs?: any, ...children: import("./VRElement").VRElementChildren) => import("./VRElement").default;
3+
Fragment: null;
4+
};
5+
export default VRDOM;

lib/dom/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use strict";
2+
/*
3+
* Telegram V
4+
* Copyright (C) 2020 Davyd Kohut
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
var __importDefault = (this && this.__importDefault) || function (mod) {
20+
return (mod && mod.__esModule) ? mod : { "default": mod };
21+
};
22+
Object.defineProperty(exports, "__esModule", { value: true });
23+
const createElement_1 = __importDefault(require("./createElement"));
24+
const VRDOM = {
25+
createElement: createElement_1.default,
26+
Fragment: null
27+
};
28+
exports.default = VRDOM;

lib/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

lib/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use strict";
2+
/*
3+
* Telegram V
4+
* Copyright (C) 2020 Davyd Kohut
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
var __importDefault = (this && this.__importDefault) || function (mod) {
20+
return (mod && mod.__esModule) ? mod : { "default": mod };
21+
};
22+
Object.defineProperty(exports, "__esModule", { value: true });
23+
// WIP
24+
const dom_1 = __importDefault(require("./dom"));
25+
const div = dom_1.default.createElement("div", null, dom_1.default.createElement("ul", {
26+
className: "list"
27+
}, dom_1.default.createElement("li", null, "a"), dom_1.default.createElement("li", null, "b"), dom_1.default.createElement("li", null, "c"), dom_1.default.createElement("li", null, "d", dom_1.default.createElement("div", null, dom_1.default.createElement("a", { href: "gogol" }, "gogol")))), dom_1.default.createElement("b", null, "123"), dom_1.default.createElement("hr", null), dom_1.default.createElement("svg", null));
28+
console.log("X", div);

0 commit comments

Comments
 (0)