-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add framework - DLight.js #222
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0e0e01c
feat: add framework - DLight.js
IanDxSSXX 1218614
fix: using eslint-parser to resolve decorator error
IanDxSSXX 9e2394c
fix: some inconsistent impl
IanDxSSXX 2256754
fix: inconsistent coding style
IanDxSSXX 606cdd8
fix: main packagename to @dlightjs/dlight
IanDxSSXX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { View } from '@dlightjs/dlight'; | ||
|
||
@View | ||
class Name { | ||
name = 'John'; | ||
|
||
Body() { | ||
h1(`Hello ${this.name}`) | ||
} | ||
} | ||
|
||
export default Name; | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { View } from "@dlightjs/dlight"; | ||
|
||
@View | ||
class Name { | ||
name = "John"; | ||
willMount() { | ||
this.name = "Jane"; | ||
} | ||
|
||
Body() { | ||
h1(`Hello ${this.name}`); | ||
} | ||
} | ||
|
||
export default Name; |
13 changes: 13 additions & 0 deletions
13
content/1-reactivity/3-computed-state/dlight/DoubleCount.view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { View } from '@dlightjs/dlight'; | ||
|
||
@View | ||
class DoubleCount { | ||
count = 10; | ||
doubleCount = this.count * 2; | ||
|
||
Body() { | ||
div(this.doubleCount) | ||
} | ||
} | ||
|
||
export default DoubleCount; |
10 changes: 10 additions & 0 deletions
10
content/2-templating/1-minimal-template/dlight/HelloWorld.view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { View } from '@dlightjs/dlight'; | ||
|
||
@View | ||
class HelloWorld { | ||
Body() { | ||
h1('Hello World') | ||
} | ||
} | ||
|
||
export default HelloWorld; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { View } from "@dlightjs/dlight"; | ||
import "./style.css"; | ||
|
||
@View | ||
class CssStyle { | ||
Body() { | ||
h1("I am red").class("title"); | ||
button("I am a button").style({ fontSize: "10rem" }); | ||
} | ||
} | ||
|
||
export default CssStyle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.title { | ||
color: red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { View } from '@dlightjs/dlight'; | ||
|
||
@View | ||
class Colors { | ||
colors = ['red', 'green', 'blue']; | ||
|
||
Body() { | ||
ul(); { | ||
for (const color of this.colors) { | ||
li(color); | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default Colors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { View } from "@dlightjs/dlight"; | ||
|
||
@View | ||
class Counter { | ||
count = 0; | ||
incrementCount() { | ||
this.count++; | ||
} | ||
|
||
Body() { | ||
p(`Counter: ${this.count}`); | ||
button("+1").onClick(this.incrementCount); | ||
} | ||
} | ||
|
||
export default Counter; |
15 changes: 15 additions & 0 deletions
15
content/2-templating/5-dom-ref/dlight/InputFocused.view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { View } from "@dlightjs/dlight"; | ||
|
||
@View | ||
class InputFocused { | ||
inputElement; | ||
didMount() { | ||
this.inputElement.focus(); | ||
} | ||
|
||
Body() { | ||
input().type("text").element(this.inputElement); | ||
} | ||
} | ||
|
||
export default InputFocused; |
30 changes: 30 additions & 0 deletions
30
content/2-templating/6-conditional/dlight/TrafficLight.view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { View } from "@dlightjs/dlight"; | ||
|
||
const TRAFFIC_LIGHTS = ["red", "orange", "green"]; | ||
|
||
@View | ||
class TrafficLight { | ||
lightIndex = 0; | ||
light = TRAFFIC_LIGHTS[this.lightIndex]; | ||
nextLight() { | ||
this.lightIndex = (this.lightIndex + 1) % TRAFFIC_LIGHTS.length; | ||
} | ||
|
||
Body() { | ||
button("Next light").onClick(this.nextLight); | ||
p(`Light is: ${this.light}`); | ||
p(); | ||
{ | ||
("You must"); | ||
if (this.light === "red") { | ||
span("STOP"); | ||
} else if (this.light === "orange") { | ||
span("SLOW DOWN"); | ||
} else if (this.light === "green") { | ||
span("GO"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default TrafficLight; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { View } from "@dlightjs/dlight"; | ||
|
||
@View | ||
class PageTitle { | ||
pageTitle = ""; | ||
didMount() { | ||
this.pageTitle = document.title; | ||
} | ||
|
||
Body() { | ||
p(`Page title: ${this.pageTitle}`); | ||
} | ||
} | ||
|
||
export default PageTitle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { View } from "@dlightjs/dlight"; | ||
|
||
@View | ||
class Time { | ||
time = new Date().toLocaleTimeString(); | ||
timer = setInterval(() => { | ||
this.time = new Date().toLocaleTimeString(); | ||
}, 1000); | ||
willUnmount() { | ||
clearInterval(this.timer); | ||
} | ||
|
||
Body() { | ||
p(`Current time: ${this.time}`); | ||
} | ||
} | ||
|
||
export default Time; |
15 changes: 15 additions & 0 deletions
15
content/4-component-composition/1-props/dlight/App.view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { View } from "@dlightjs/dlight"; | ||
import UserProfile from "./UserProfile.view"; | ||
|
||
@View | ||
class App { | ||
Body() { | ||
UserProfile() | ||
.name("John") | ||
.age(20) | ||
.favouriteColors(["green", "blue", "red"]) | ||
.isAvailable(true); | ||
} | ||
} | ||
|
||
export default App; |
18 changes: 18 additions & 0 deletions
18
content/4-component-composition/1-props/dlight/UserProfile.view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { View } from '@dlightjs/dlight'; | ||
|
||
@View | ||
class UserProfile { | ||
@Prop name = ''; | ||
@Prop age = null; | ||
@Prop favouriteColors = []; | ||
@Prop isAvailable = false; | ||
|
||
Body() { | ||
p(`My name is ${this.name}!`) | ||
p(`My age is ${this.age}!`) | ||
p(`My favourite colors are ${this.favouriteColors.join(', ')}!`) | ||
p(`I am ${this.isAvailable ? 'available' : 'not available'}`) | ||
} | ||
} | ||
|
||
export default UserProfile; |
21 changes: 21 additions & 0 deletions
21
content/4-component-composition/2-emit-to-parent/dlight/App.view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { View } from "@dlightjs/dlight"; | ||
import AnswerButton from "./HelloWorld.view"; | ||
|
||
@View | ||
class App { | ||
isHappy = true; | ||
onAnswerNo() { | ||
this.isHappy = false; | ||
} | ||
onAnswerYes() { | ||
this.isHappy = true; | ||
} | ||
|
||
Body() { | ||
p("Are you happy?"); | ||
AnswerButton().onYes(this.onAnswerYes).onNo(this.onAnswerNo); | ||
p(this.isHappy ? "😀" : "😥").style({ fontSize: "50px" }); | ||
} | ||
} | ||
|
||
export default App; |
16 changes: 16 additions & 0 deletions
16
content/4-component-composition/2-emit-to-parent/dlight/HelloWorld.view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { View } from '@dlightjs/dlight'; | ||
|
||
@View | ||
class AnswerButton { | ||
@Prop onYes; | ||
@Prop onNo; | ||
|
||
Body() { | ||
button('Yes') | ||
.onClick(this.onYes) | ||
button('No') | ||
.onClick(this.onNo) | ||
} | ||
} | ||
|
||
export default AnswerButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { View } from '@dlightjs/dlight'; | ||
import FunnyButton from './FunnyButton.view'; | ||
|
||
@View | ||
class App { | ||
Body() { | ||
FunnyButton(); { | ||
"Click me!" | ||
} | ||
} | ||
} | ||
|
||
export default App; |
27 changes: 27 additions & 0 deletions
27
content/4-component-composition/3-slot/dlight/FunnyButton.view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { View } from '@dlightjs/dlight'; | ||
|
||
@View | ||
class FunnyButton { | ||
@Children children | ||
|
||
Body() { | ||
button() | ||
.style({ | ||
background: "rgba(0, 0, 0, 0.4)", | ||
color: "#fff", | ||
padding: "10px 20px", | ||
fontSize: "30px", | ||
border: "2px solid #fff", | ||
margin: "8px", | ||
transform: "scale(0.9)", | ||
boxShadow: "4px 4px rgba(0, 0, 0, 0.4)", | ||
transition: "transform 0.2s cubic-bezier(0.34, 1.65, 0.88, 0.925) 0s", | ||
outline: "0", | ||
}) | ||
{ | ||
this.children | ||
} | ||
} | ||
} | ||
|
||
export default FunnyButton; |
14 changes: 14 additions & 0 deletions
14
content/4-component-composition/4-slot-fallback/dlight/App.view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { View } from '@dlightjs/dlight'; | ||
import FunnyButton from './FunnyButton.view'; | ||
|
||
@View | ||
class App { | ||
Body() { | ||
FunnyButton() | ||
FunnyButton(); { | ||
"I got content!" | ||
} | ||
} | ||
} | ||
|
||
export default App; |
31 changes: 31 additions & 0 deletions
31
content/4-component-composition/4-slot-fallback/dlight/FunnyButton.view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { View } from '@dlightjs/dlight'; | ||
|
||
@View | ||
class FunnyButton { | ||
@Children children | ||
|
||
Body() { | ||
button() | ||
.style({ | ||
background: "rgba(0, 0, 0, 0.4)", | ||
color: "#fff", | ||
padding: "10px 20px", | ||
fontSize: "30px", | ||
border: "2px solid #fff", | ||
margin: "8px", | ||
transform: "scale(0.9)", | ||
boxShadow: "4px 4px rgba(0, 0, 0, 0.4)", | ||
transition: "transform 0.2s cubic-bezier(0.34, 1.65, 0.88, 0.925) 0s", | ||
outline: "0", | ||
}) | ||
{ | ||
if (this.children) { | ||
this.children | ||
} else { | ||
span('No content found') | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default FunnyButton; |
24 changes: 24 additions & 0 deletions
24
content/4-component-composition/5-context/dlight/App.view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { View } from "@dlightjs/dlight"; | ||
import UserProfile from "./UserProfile.view"; | ||
|
||
@View | ||
class App { | ||
user = { | ||
id: 1, | ||
username: "unicorn42", | ||
email: "[email protected]", | ||
}; | ||
updateUserName(newUsername) { | ||
this.user.username = newUsername; | ||
} | ||
|
||
Body() { | ||
h1(`Welcome back, ${this.user.username}`); | ||
env().user(this.user).updateUserName(this.updateUserName); | ||
{ | ||
UserProfile(); | ||
} | ||
} | ||
} | ||
|
||
export default App; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By curiosity, why did you choose to
export default
like this instead ofexport default class Name {
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In dlight, we use class to declare a component and use
function call
to use one:This is fine in js. But in ts, this'll arise syntax level errors(even though it's working, but it's ugly in your editor). To we need to force type casting to a self-returning function, which'll resolve this error and give you props auto-completion. But in ts you can't
export class {} as xxx
. So we do it like:And here
Pretty
is just an alias of "any" to make the typing pretty. I mean make it "as pretty as" your type...