wowojs 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +23 -0
- package/example/main.js +6 -0
- package/example/sawit.js +76 -0
- package/package.json +15 -0
- package/src/component.js +90 -0
- package/src/history.js +21 -0
- package/src/index.d.ts +95 -0
- package/src/index.js +5 -0
- package/src/reducer.js +24 -0
- package/src/render.js +41 -0
- package/src/state.js +81 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Devied Rahmadsyah
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Wowo.js
|
|
2
|
+
Wowo.js adalah sebuah library yang difokuskan untuk kemudahan membuat *Web Component* yang lebih ringkas dan menggunakan state global yang disimpan di *Session Storage* untuk meminimalkan kode yang rumit daripada MBG yang terlalu rumit ngurus anggaran.
|
|
3
|
+
|
|
4
|
+
### berikut panduan dasar Wowo.js
|
|
5
|
+
|
|
6
|
+
##### Membuat Component
|
|
7
|
+
membuat component menggunakan $BuatWilayah
|
|
8
|
+
```js
|
|
9
|
+
import { $BuatWilayah } from "wowo"
|
|
10
|
+
$BuatWilayah({
|
|
11
|
+
namaWilayah: "sumatra",
|
|
12
|
+
isiWilayah: () => {
|
|
13
|
+
return `
|
|
14
|
+
<h1>Halo dunia</h1>
|
|
15
|
+
`
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
cara menjalankannya di file .html
|
|
21
|
+
````html
|
|
22
|
+
<wowo-sumatra></wowo-sumatra>
|
|
23
|
+
````
|
package/example/main.js
ADDED
package/example/sawit.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/// INI HANYA CONTOH
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
$antek2,
|
|
5
|
+
$BuatWilayah,
|
|
6
|
+
$PecatAntek2,
|
|
7
|
+
$Sejarah,
|
|
8
|
+
$UrusKeuangan,
|
|
9
|
+
} from "./src";
|
|
10
|
+
export function sawit() {
|
|
11
|
+
let sawit = $antek2("sawit", 100);
|
|
12
|
+
const reducer = (aksi) => {
|
|
13
|
+
switch (aksi.tipe) {
|
|
14
|
+
case "TAMBAH":
|
|
15
|
+
return (sawit = $antek2("sawit", (t) => t + 100));
|
|
16
|
+
case "KURANG":
|
|
17
|
+
return (sawit = $antek2("sawit", (t) => (t >= 100 ? t - 100 : 0)));
|
|
18
|
+
case "RESET":
|
|
19
|
+
if (sawit === undefined) {
|
|
20
|
+
return 0;
|
|
21
|
+
} else {
|
|
22
|
+
sawit = $PecatAntek2("sawit") || 0;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
$BuatWilayah({
|
|
27
|
+
namaWilayah: "sumatra",
|
|
28
|
+
isiWilayah: () => {
|
|
29
|
+
return /*html*/ `
|
|
30
|
+
<div class="bg">
|
|
31
|
+
<h1>Ssumatra</h1>
|
|
32
|
+
<main>
|
|
33
|
+
<p>Total sawit: ${sawit || 0}</p>
|
|
34
|
+
<button @click="tambah">Tambah</button>
|
|
35
|
+
<button @click="kurang">Kurang</button>
|
|
36
|
+
<button @click="reset">Reset</button>
|
|
37
|
+
<button @click="debug">Debug</button>
|
|
38
|
+
</main>
|
|
39
|
+
</div>
|
|
40
|
+
`;
|
|
41
|
+
},
|
|
42
|
+
methods: {
|
|
43
|
+
tambah() {
|
|
44
|
+
$UrusKeuangan(reducer, { tipe: "TAMBAH" });
|
|
45
|
+
},
|
|
46
|
+
kurang() {
|
|
47
|
+
$UrusKeuangan(reducer, { tipe: "KURANG" });
|
|
48
|
+
},
|
|
49
|
+
reset() {
|
|
50
|
+
$UrusKeuangan(reducer, { tipe: "RESET" });
|
|
51
|
+
},
|
|
52
|
+
debug() {
|
|
53
|
+
$Sejarah({ aktif: true });
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
style: /*css*/ `
|
|
57
|
+
.bg{
|
|
58
|
+
background: linear-gradient(45deg, #8cc7e9, #f03737);
|
|
59
|
+
text-align: center;
|
|
60
|
+
color: #ffffff;
|
|
61
|
+
width: 100vw;
|
|
62
|
+
height: 100vh;
|
|
63
|
+
}
|
|
64
|
+
h1{
|
|
65
|
+
margin-bottom: 100px;
|
|
66
|
+
}
|
|
67
|
+
button{
|
|
68
|
+
border-radius: 30px;
|
|
69
|
+
text-align: center;
|
|
70
|
+
font-size: 17px;
|
|
71
|
+
background: #95f8e3;
|
|
72
|
+
border: none
|
|
73
|
+
}
|
|
74
|
+
`,
|
|
75
|
+
});
|
|
76
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wowojs",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Wowo.js adalah sebuah library yang difokuskan untuk kemudahan membuat *Web Component* yang lebih ringkas dan menggunakan state global yang disimpan di *Session Storage* untuk meminimalkan kode yang rumit daripada MBG yang terlalu rumit ngurus anggaran.",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"directories": {
|
|
7
|
+
"example": "example"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
},
|
|
12
|
+
"author": "Devied Rahmadsyah",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"types": "./src/index.d.ts"
|
|
15
|
+
}
|
package/src/component.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { $Sejarah } from "./history";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Buat wilayah untuk membuat kekuasaan pakai komponen (Web Component)
|
|
5
|
+
* dengan sistem event handling otomatis menggunakan tanda '$'.
|
|
6
|
+
* @param {Object} options - Konfigurasi wilayah.
|
|
7
|
+
* @param {string} options.namaWilayah - Nama unik untuk komponen (akan menjadi tag wowo-nama).
|
|
8
|
+
* @param {Function|string} options.isiWilayah - Konten HTML atau fungsi yang mengembalikan template string.
|
|
9
|
+
* @param {Object} [options.methods={}] - Kumpulan fungsi yang bisa dipanggil oleh atribut event ($click, $input, dll).
|
|
10
|
+
* @param {string} [options.deskripsi] - Catatan opsional mengenai tujuan wilayah.
|
|
11
|
+
* @param {string} [options.style] - Styling css kamu
|
|
12
|
+
* @example
|
|
13
|
+
* let sawit = 1000;
|
|
14
|
+
* const aksi = {
|
|
15
|
+
* tambah() { sawit += 100; }
|
|
16
|
+
* };
|
|
17
|
+
* $BuatWilayah({
|
|
18
|
+
* namaWilayah: "sumatra",
|
|
19
|
+
* methods: aksi,
|
|
20
|
+
* isiWilayah: () => {
|
|
21
|
+
* return `
|
|
22
|
+
* <h1>sawit di sumatra ada ${sawit}</h1>
|
|
23
|
+
* <button $click="tambah">Tambah sawit</button>
|
|
24
|
+
* `;
|
|
25
|
+
* }
|
|
26
|
+
* });
|
|
27
|
+
* @author Devied Rahmadsyah
|
|
28
|
+
* @license MIT
|
|
29
|
+
*/
|
|
30
|
+
export function $BuatWilayah({
|
|
31
|
+
namaWilayah,
|
|
32
|
+
isiWilayah,
|
|
33
|
+
style = "",
|
|
34
|
+
methods = {},
|
|
35
|
+
deskripsi,
|
|
36
|
+
}) {
|
|
37
|
+
$Sejarah({
|
|
38
|
+
modul: "Component: $BuatWilayah",
|
|
39
|
+
detail: {
|
|
40
|
+
namaWilayah: namaWilayah,
|
|
41
|
+
isiWilayah: isiWilayah,
|
|
42
|
+
style: style || "tidak ada",
|
|
43
|
+
methods: methods || "tidak ada",
|
|
44
|
+
deskripsi: deskripsi || "tidak ada",
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
const tagName = `wowo-${namaWilayah.toLowerCase()}`;
|
|
48
|
+
if (customElements.get(tagName)) return;
|
|
49
|
+
|
|
50
|
+
customElements.define(
|
|
51
|
+
tagName,
|
|
52
|
+
class extends HTMLElement {
|
|
53
|
+
constructor() {
|
|
54
|
+
super();
|
|
55
|
+
this.attachShadow({ mode: "open" });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
connectedCallback() {
|
|
59
|
+
this.render();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
render() {
|
|
63
|
+
const konten =
|
|
64
|
+
typeof isiWilayah === "function" ? isiWilayah() : isiWilayah;
|
|
65
|
+
let css = style ? `<style>${style}</style>` : "";
|
|
66
|
+
this.shadowRoot.innerHTML = konten + css;
|
|
67
|
+
|
|
68
|
+
const allElements = this.shadowRoot.querySelectorAll("*");
|
|
69
|
+
|
|
70
|
+
allElements.forEach((el) => {
|
|
71
|
+
[...el.attributes].forEach((attr) => {
|
|
72
|
+
if (attr.name.startsWith("@")) {
|
|
73
|
+
const eventType = attr.name.slice(1);
|
|
74
|
+
const functionName = attr.value.replace("()", "");
|
|
75
|
+
|
|
76
|
+
if (methods[functionName]) {
|
|
77
|
+
el.addEventListener(eventType, (e) => {
|
|
78
|
+
methods[functionName](e);
|
|
79
|
+
this.render();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
el.removeAttribute(attr.name);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
);
|
|
90
|
+
}
|
package/src/history.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
let history = [];
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Lihat sejarah penggunaan library ini
|
|
5
|
+
* @param {Object} opsi
|
|
6
|
+
* @param {string} opsi.modul
|
|
7
|
+
* @param {string} opsi.detail
|
|
8
|
+
* @param {boolean} [opsi.aktif=false] - Jika true, tabel sejarah akan muncul di console
|
|
9
|
+
* @license MIT
|
|
10
|
+
* @author Devied Rahmadsyah
|
|
11
|
+
*/
|
|
12
|
+
export function $Sejarah({ modul, detail, aktif = false }) {
|
|
13
|
+
history.push({
|
|
14
|
+
waktu: new Date().toLocaleTimeString(),
|
|
15
|
+
modul,
|
|
16
|
+
detail,
|
|
17
|
+
});
|
|
18
|
+
if (aktif) {
|
|
19
|
+
console.dir(history);
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State sederhana untuk antek-antek wowo
|
|
3
|
+
* @param {string} name nama antek nya
|
|
4
|
+
* @param {any} value isi identitas dia
|
|
5
|
+
* @example
|
|
6
|
+
* const antek = $antek2("antek", 1)
|
|
7
|
+
* function addAntek(){
|
|
8
|
+
* antek = $antek2("antek",(antek2) => {
|
|
9
|
+
* antek2 += 1
|
|
10
|
+
* })
|
|
11
|
+
* }
|
|
12
|
+
* @license MIT
|
|
13
|
+
* @author Devied Rahmadsyah
|
|
14
|
+
*/
|
|
15
|
+
export declare function $antek2(name: string, value: any, ...args: any[]): any;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Render component agar bisa membangun ekonomi
|
|
19
|
+
* @param {string|string[]} options.components ambil component untuk component yang ingin dirender
|
|
20
|
+
* @example
|
|
21
|
+
* function addSawit(){
|
|
22
|
+
* sawit + 12
|
|
23
|
+
* $BangunEkonomi("wowo-sumatra")
|
|
24
|
+
* }
|
|
25
|
+
* @license MIT
|
|
26
|
+
* @author Devied Rahmadsyah
|
|
27
|
+
*/
|
|
28
|
+
export declare function $BangunEkonomi(components: any): void;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Buat wilayah untuk membuat kekuasaan pakai komponen (Web Component)
|
|
32
|
+
* dengan sistem event handling otomatis menggunakan tanda '$'.
|
|
33
|
+
* @param {Object} options - Konfigurasi wilayah.
|
|
34
|
+
* @param {string} options.namaWilayah - Nama unik untuk komponen (akan menjadi tag wowo-nama).
|
|
35
|
+
* @param {Function|string} options.isiWilayah - Konten HTML atau fungsi yang mengembalikan template string.
|
|
36
|
+
* @param {Object} [options.methods={}] - Kumpulan fungsi yang bisa dipanggil oleh atribut event ($click, $input, dll).
|
|
37
|
+
* @param {string} [options.deskripsi] - Catatan opsional mengenai tujuan wilayah.
|
|
38
|
+
* @param {string} [options.style] - Styling css kamu
|
|
39
|
+
* @example
|
|
40
|
+
* let sawit = 1000;
|
|
41
|
+
* const aksi = {
|
|
42
|
+
* tambah() { sawit += 100; }
|
|
43
|
+
* };
|
|
44
|
+
* $BuatWilayah({
|
|
45
|
+
* namaWilayah: "sumatra",
|
|
46
|
+
* methods: aksi,
|
|
47
|
+
* isiWilayah: () => {
|
|
48
|
+
* return `
|
|
49
|
+
* <h1>sawit di sumatra ada ${sawit}</h1>
|
|
50
|
+
* <button $click="tambah">Tambah sawit</button>
|
|
51
|
+
* `;
|
|
52
|
+
* }
|
|
53
|
+
* });
|
|
54
|
+
* @author Devied Rahmadsyah
|
|
55
|
+
* @license MIT
|
|
56
|
+
*/
|
|
57
|
+
export declare function $BuatWilayah({ namaWilayah, isiWilayah, style, methods, deskripsi, }: {
|
|
58
|
+
namaWilayah: string;
|
|
59
|
+
isiWilayah: Function | string;
|
|
60
|
+
methods?: Object | undefined;
|
|
61
|
+
deskripsi?: string | undefined;
|
|
62
|
+
style?: string | undefined;
|
|
63
|
+
}): void;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Pecat antek-antek yang berulah
|
|
67
|
+
* @param {string} name Hapus antek-antek yang ada
|
|
68
|
+
* @example
|
|
69
|
+
* $PecatAntek2("mul")
|
|
70
|
+
*/
|
|
71
|
+
export declare function $PecatAntek2(name: string): void;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Lihat sejarah penggunaan library ini
|
|
75
|
+
* @param {Object} opsi
|
|
76
|
+
* @param {string} opsi.modul
|
|
77
|
+
* @param {string} opsi.detail
|
|
78
|
+
* @param {boolean} [opsi.aktif=false] - Jika true, tabel sejarah akan muncul di console
|
|
79
|
+
* @license MIT
|
|
80
|
+
* @author Devied Rahmadsyah
|
|
81
|
+
*/
|
|
82
|
+
export declare function $Sejarah({ modul, detail, aktif }: {
|
|
83
|
+
modul: string;
|
|
84
|
+
detail: string;
|
|
85
|
+
aktif?: boolean | undefined;
|
|
86
|
+
}): void;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Reducer bawaan wowojs
|
|
90
|
+
* @license MIT
|
|
91
|
+
* @author Devied Rahmadsyah
|
|
92
|
+
*/
|
|
93
|
+
export declare function $UrusKeuangan(reducer: any, action: any): any;
|
|
94
|
+
|
|
95
|
+
export { }
|
package/src/index.js
ADDED
package/src/reducer.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { $Sejarah } from "./history";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Reducer bawaan wowojs
|
|
5
|
+
* @license MIT
|
|
6
|
+
* @author Devied Rahmadsyah
|
|
7
|
+
*/
|
|
8
|
+
export function $UrusKeuangan(reducer, action) {
|
|
9
|
+
$Sejarah({
|
|
10
|
+
modul: "Reducer: $UrusKeuangan",
|
|
11
|
+
detail: [
|
|
12
|
+
{
|
|
13
|
+
reducer: reducer,
|
|
14
|
+
action: action,
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
});
|
|
18
|
+
try {
|
|
19
|
+
return reducer(action);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.error(`terjadi error ${reducer}
|
|
22
|
+
${error}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/render.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { $Sejarah } from "./history";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Render component agar bisa membangun ekonomi
|
|
5
|
+
* @param {string|string[]} options.components ambil component untuk component yang ingin dirender
|
|
6
|
+
* @example
|
|
7
|
+
* function addSawit(){
|
|
8
|
+
* sawit + 12
|
|
9
|
+
* $BangunEkonomi("wowo-sumatra")
|
|
10
|
+
* }
|
|
11
|
+
* @license MIT
|
|
12
|
+
* @author Devied Rahmadsyah
|
|
13
|
+
*/
|
|
14
|
+
export function $BangunEkonomi(components) {
|
|
15
|
+
$Sejarah({
|
|
16
|
+
modul: "Render: $BangunEkonomi",
|
|
17
|
+
detail: components,
|
|
18
|
+
});
|
|
19
|
+
if (Array.isArray(components)) {
|
|
20
|
+
components.forEach((comp) => {
|
|
21
|
+
const selector = typeof comp === "string" ? comp : comp;
|
|
22
|
+
eksekusi(selector);
|
|
23
|
+
});
|
|
24
|
+
} else {
|
|
25
|
+
eksekusi(components);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function eksekusi(components) {
|
|
29
|
+
const element = document.querySelector(components);
|
|
30
|
+
if (element && typeof element.render === "function") {
|
|
31
|
+
element.render();
|
|
32
|
+
} else {
|
|
33
|
+
document.addEventListener(
|
|
34
|
+
"DOMContentLoaded",
|
|
35
|
+
() => {
|
|
36
|
+
if (element) element.render();
|
|
37
|
+
},
|
|
38
|
+
{ once: true },
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/state.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { $Sejarah } from "./history";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* State sederhana untuk antek-antek wowo
|
|
5
|
+
* @param {string} name nama antek nya
|
|
6
|
+
* @param {any} value isi identitas dia
|
|
7
|
+
* @example
|
|
8
|
+
* const antek = $antek2("antek", 1)
|
|
9
|
+
* function addAntek(){
|
|
10
|
+
* antek = $antek2("antek",(antek2) => {
|
|
11
|
+
* antek2 += 1
|
|
12
|
+
* })
|
|
13
|
+
* }
|
|
14
|
+
* @license MIT
|
|
15
|
+
* @author Devied Rahmadsyah
|
|
16
|
+
*/
|
|
17
|
+
export function $antek2(name, value) {
|
|
18
|
+
$Sejarah({
|
|
19
|
+
modul: "State: $antek2",
|
|
20
|
+
detail: {
|
|
21
|
+
nama: name,
|
|
22
|
+
value: value,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
const dataLama = sessionStorage.getItem(name);
|
|
26
|
+
let parsedLama = null;
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
if (dataLama !== null) {
|
|
30
|
+
parsedLama = JSON.parse(dataLama);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (typeof value === "function") {
|
|
34
|
+
const newValue = value(parsedLama);
|
|
35
|
+
sessionStorage.setItem(name, JSON.stringify(newValue));
|
|
36
|
+
return newValue;
|
|
37
|
+
} else if (arguments.length === 1) {
|
|
38
|
+
return parsedLama;
|
|
39
|
+
} else {
|
|
40
|
+
sessionStorage.setItem(name, JSON.stringify(value));
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
} catch (e) {
|
|
44
|
+
console.error(`Gagal memproses JSON untuk "${name}", mereset data...`, e);
|
|
45
|
+
if (arguments.length > 1) {
|
|
46
|
+
const defaultValue = typeof value === "function" ? value(null) : value;
|
|
47
|
+
sessionStorage.setItem(name, JSON.stringify(defaultValue));
|
|
48
|
+
return defaultValue;
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Pecat antek-antek yang berulah
|
|
56
|
+
* @param {string} name Hapus antek-antek yang ada
|
|
57
|
+
* @example
|
|
58
|
+
* $PecatAntek2("mul")
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
export function $PecatAntek2(name) {
|
|
62
|
+
$Sejarah({
|
|
63
|
+
modul: "State: $PecatAntek2",
|
|
64
|
+
detail: {
|
|
65
|
+
nama: name,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
if (typeof name !== "string" || !name.trim()) {
|
|
69
|
+
console.warn(`Nama tidak valid: ${name}`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (sessionStorage.getItem(name) === null) {
|
|
73
|
+
console.info(`Key "${name}" tidak ditemukan, tidak ada yang dihapus.`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
sessionStorage.removeItem(name);
|
|
78
|
+
} catch (e) {
|
|
79
|
+
console.error(`Gagal menghapus ${name}:`, e);
|
|
80
|
+
}
|
|
81
|
+
}
|