Skip to content

Commit 0df4c34

Browse files
authored
Merge pull request #19 from UnSetSoft/dev
1.1.10
2 parents ebc6304 + 953fddf commit 0df4c34

7 files changed

Lines changed: 133 additions & 61 deletions

File tree

.npmignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/node_modules
22
/yarn.lock
3-
/src
3+
/src/server.js
4+
/src/public
5+
46
/.vscode
57
/.github

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.1.5",
2+
"version": "1.1.10",
33
"main": "./src/lib/main.js",
44
"scripts": {
55
"dev": "nodemon ./src/server.js",

src/lib/hooks/store.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Store {
2+
constructor(defvalue) {
3+
this.defvalue = defvalue;
4+
}
5+
/* `setValue` is a method that takes in a parameter `newValue`. The arrow function syntax `=>` is
6+
used to define the function. Inside the function, the `defvalue` property of the `Store` instance
7+
is set to the `newValue` parameter. This means that when `setValue` is called with a new value, it
8+
updates the `defvalue` property of the `Store` instance to that new value. */
9+
setValue = (newValue) => (this.defvalue = newValue);
10+
11+
/* `hook` is a method that returns an array containing two functions: `getValue` and `setValue`.
12+
These functions can be used to get and set the value of the `defvalue` property of the `Store`
13+
class instance. This is useful for implementing state management in React functional components
14+
using the `useState` hook. */
15+
hook = () => {
16+
return [this.defvalue, this.setValue];
17+
};
18+
}
19+
20+
export default Store;

src/lib/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Ryunix from "./ryunix/index.js";
22
const _r = (el) => new Ryunix(el);
3-
43
window._r = _r;
54

5+
66
export default _r;
7-
export { Ryunix };
7+
export { Ryunix};

src/lib/ryunix/index.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Remote from "../remote/index.js";
22
import Animate from "../animate/index.js";
3+
import Store from "../hooks/store.js";
34
class Ryunix {
45
/**
56
* The constructor function takes in an element and assigns it to the elements property of the
@@ -68,11 +69,43 @@ class Ryunix {
6869
* @param html - The HTML to insert.
6970
* @returns the value of the variable ins.
7071
*/
71-
insertHTML(html) {
72+
insertsHTML(html) {
7273
this.getElements().forEach((el) => (el.innerHTML += html));
7374
return this;
7475
}
7576

77+
/**
78+
* The function appends text to the inner text of all elements returned by a selector.
79+
* @param txt - txt is a parameter that represents the text that will be inserted into the innerText
80+
* property of the selected elements.
81+
* @returns the current object (`this`) to allow for method chaining.
82+
*/
83+
insertsTXT(txt) {
84+
this.getElements().forEach((el) => (el.innerText += txt));
85+
return this;
86+
}
87+
88+
/**
89+
* The function sets the inner text of an element and returns the element.
90+
* @param txt - The text that will be inserted into the element's inner text.
91+
* @returns the object that called it, which is likely an instance of a class or an object with a
92+
* similar structure.
93+
*/
94+
insertTXT(txt) {
95+
this.getElement().innerText = txt;
96+
return this;
97+
}
98+
99+
/**
100+
* The function inserts HTML code into an element's innerHTML property and returns the element.
101+
* @param html - The HTML code that will be inserted into the element's innerHTML property.
102+
* @returns The object that the `insertHTML` method belongs to is being returned.
103+
*/
104+
insertHTML(html) {
105+
this.getElement().innerHTML = html;
106+
return this;
107+
}
108+
76109
/**
77110
* The function takes a boolean as an argument and returns a boolean.
78111
* @param boolean - true or false
@@ -213,6 +246,16 @@ class Ryunix {
213246
this.getElement().remove();
214247
return this;
215248
}
249+
250+
/**
251+
* The function returns a new instance of a Store object with a specified value and hooks it.
252+
* @param [val=null] - The val parameter is an optional initial value that can be passed to the Store
253+
* constructor. If no value is provided, the store will be initialized with a null value.
254+
* @returns A hook that creates a new instance of the Store class with an optional initial value.
255+
*/
256+
useStore(val = null) {
257+
return new Store(val).hook();
258+
}
216259
}
217260

218261
export default Ryunix;

src/public/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
<button id="rotate" class="kg__button">
5656
Custom animation (rotation)
5757
</button>
58+
59+
<button id="increment" class="kg__button">
60+
<span id="count"></span>
61+
</button>
5862
</div>
5963

6064
<ul id="coffe"></ul>

src/public/main.js

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,79 @@
1-
_k().load(() => {
2-
_k('#hot').event('click', async () => {
3-
4-
_k("#hot").removeClass("kg-primary")
1+
_r().load(() => {
2+
_r("#hot").event("click", async () => {
3+
_r("#hot").removeClass("kg-primary");
54

6-
const { tag } = _k('#hot').getDataSet()
5+
const { tag } = _r("#hot").getDataSet();
76

8-
_k('#coffe').removeChildrens()
7+
_r("#coffe").removeChildrens();
98

10-
const r = await _k().remote(`https://api.sampleapis.com/coffee/${tag}`).get();
11-
12-
r.map(r => {
13-
_k('#coffe').insertHTML(`<li><b>${r.title}:</b> ${r.description}</li>`)
14-
})
15-
16-
_k('#hot').disableElement(true)
9+
const r = await _r()
10+
.remote(`https://api.sampleapis.com/coffee/${tag}`)
11+
.get();
1712

18-
_k('#iced').disableElement(false)
13+
r.map((r) => {
14+
_r("#coffe").insertHTML(`<li><b>${r.title}:</b> ${r.description}</li>`);
15+
});
1916

20-
_k('#clear').disableElement(false)
17+
_r("#hot").disableElement(true);
2118

22-
})
19+
_r("#iced").disableElement(false);
2320

24-
_k('#iced').event('click', async () => {
21+
_r("#clear").disableElement(false);
22+
});
2523

26-
const { tag } = _k('#iced').getDataSet()
24+
_r("#iced").event("click", async () => {
25+
const { tag } = _r("#iced").getDataSet();
2726

28-
_k('#coffe').removeChildrens()
27+
_r("#coffe").removeChildrens();
2928

30-
const r = await _k().remote(`https://api.sampleapis.com/coffee/_k{tag}`).get();
31-
32-
r.map(r => {
33-
_k('#coffe').insertHTML(`<li><b>_k{r.title}:</b> _k{r.description}</li>`)
34-
})
35-
36-
_k('#iced').disableElement(true)
37-
_k('#hot').disableElement(false)
38-
_k('#clear').disableElement(false)
39-
})
29+
const r = await _r()
30+
.remote(`https://api.sampleapis.com/coffee/_r{tag}`)
31+
.get();
4032

41-
_k('#clear').event('click', async () => {
33+
r.map((r) => {
34+
_r("#coffe").insertHTML(`<li><b>_r{r.title}:</b> _r{r.description}</li>`);
35+
});
4236

43-
_k('#coffe').removeChildrens()
44-
45-
46-
_k('#iced').disableElement(false)
47-
_k('#hot').disableElement(false)
48-
_k('#clear').disableElement(true)
49-
})
37+
_r("#iced").disableElement(true);
38+
_r("#hot").disableElement(false);
39+
_r("#clear").disableElement(false);
40+
});
5041

51-
_k('#boxbtn').event('click', () => {
52-
_k('#box').toggleClass("active")
53-
})
42+
_r("#clear").event("click", async () => {
43+
_r("#coffe").removeChildrens();
5444

55-
_k('#fadeIn').event('click', () => {
56-
_k('#box').animate().fadeIn()
57-
})
45+
_r("#iced").disableElement(false);
46+
_r("#hot").disableElement(false);
47+
_r("#clear").disableElement(true);
48+
});
5849

59-
_k('#fadeOut').event('click', () => {
60-
_k('#box').animate().fadeOut()
61-
})
50+
_r("#boxbtn").event("click", () => {
51+
_r("#box").toggleClass("active");
52+
});
6253

63-
_k('#rotate').event('click', () => {
64-
65-
_k('#box').animate().anime([
66-
{transform: 'rotate(360deg)'}
67-
])
68-
})
54+
_r("#fadeIn").event("click", () => {
55+
_r("#box").animate().fadeIn();
56+
});
6957

58+
_r("#fadeOut").event("click", () => {
59+
_r("#box").animate().fadeOut();
60+
});
7061

71-
72-
73-
console.log(_k('button').getElements())
62+
_r("#rotate").event("click", () => {
63+
_r("#box")
64+
.animate()
65+
.anime([{ transform: "rotate(360deg)" }]);
66+
});
7467

68+
let [counter, setCounter] = _r().useStore(0);
7569

76-
})
70+
_r("#count").insertTXT(`${counter}`);
71+
72+
_r("#increment").event("click", () => {
73+
counter++;
74+
setCounter(counter);
75+
_r("#count").insertTXT(`${counter}`);
76+
});
77+
78+
console.log(_r("button").getElements());
79+
});

0 commit comments

Comments
 (0)