-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.html
More file actions
519 lines (495 loc) · 16.3 KB
/
docs.html
File metadata and controls
519 lines (495 loc) · 16.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="keywords" content="Javascript,vuejs, dativejs,dativejs docs,dativejs documentation, state management, framework,frontend, frontend framework, JavaScript framework,javascript library">
<link rel="shortcut icon" href="public/favicon.ico" type="image/x-icon" />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5442324990787763"
crossorigin="anonymous"></script>
<!-- Primary Meta Tags -->
<title>Docs • DativeJs</title>
<meta name="title" content="Docs • DativeJs">
<meta name="description" content="DativeJs documentation">
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://dativejs.js.org/">
<meta property="og:title" content="Docs • DativeJs">
<meta property="og:description" content="DativeJs documentation">
<meta property="og:image" content="https://dativejs.js.org/public/logo.png">
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="https://dativejs.js.org/">
<meta property="twitter:title" content="Docs • DativeJs">
<meta property="twitter:description" content="DativeJs documentation">
<meta property="twitter:image" content="https://dativejs.js.org/public/logo.png">
<link rel="stylesheet" href="css/vs2015.css">
<link rel="stylesheet" href="css/tailwind.css">
</head>
<style>
.monospace{
font-family: monospace;
}
.show{
transition: 2s;
display: block;
}
.hide{
display: none;
}
pre{
border-radius: 5px;
}
.log{
color: #ff3e00;
}
</style>
<body>
<div id="app" class="relative">
<nav class="bg-white fixed shadow w-full py-3" style="z-index: 1000">
<div class="max-w-6xl mx-auto px-4">
<div class="flex justify-between">
<div class="flex space-x-7">
<div>
<span class="absolute top-3 left-5 text-4xl md:hidden" onclick="sideopen()">☰</span>
<p class="flex items-center py-4 px-2 md:mx-5">
<img src="../public/logo.svg" alt="Logo" class="absolute top--5 left-10 h-20 w-20">
<span class="absolute left-28 font-bold text-gray-500 text-lg monospace">Dative</span>
</p>
<ul class="absolute hidden md:block right-10 top-5 md:flex md:space-x-4 mx-5 text-gray-500 z-auto">
<li><a href="/">Home</a></li><br />
<li><a href="https://github.com/dativeJs/dativejs">GitHub</a></li><br />
<li><a href="/docs.html">Docs</a></li><br />
</ul>
<span class="absolute top-3 right-10 text-4xl md:hidden" onclick="navopen()">☰</span>
</div>
</div>
</div>
</div>
</nav><br /><br /><br />
<div class="shadow-2xl bg-white border-black fixed w-2/4 right-0 top-12 md:hidden" id="nav" style="z-index: 1000;height: 0px;overflow: hidden">
<ul class="mx-5 text-gray-500 z-auto">
<li><a href="/">Home</a></li><br />
<li><a href="https://github.com/dativeJs/dativejs">GitHub</a></li><br />
<li><a href="/docs.html">Docs</a></li><br />
</ul>
</div>
<div class="py-10 bg-gray-500 text-white fixed w-0 top-12 h-screen overflow-hidden ease-in-out md:w-60 " id="sidebar" style="transition: width 1s;">
<ul class="mx-5">
<li>
<p>Essential</p>
<ul class="mx-5">
<li><a href="#instance">Instance</a></li>
<li><a href="#reactive">Reactivity</a></li>
<li><a href="#directives">Directives</a></li>
<li><a href="#create-your-own-custom-directive">Custom Directives</a></li>
<li><a href="#computed">Computed property</a></li>
<li><a href="#state-management">State Management</a></li>
<li><a href="#set">Set</a></li>
</ul>
</li>
</ul>
</div>
<div class="mx-5 md:mx-72 text-gray-600">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5442324990787763"
crossorigin="anonymous"></script>
<!-- new ads -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-5442324990787763"
data-ad-slot="1918194121"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<h1 class="text-2xl" id="instance">INSTANCE</h1><br />
<p>Building a Ui with Dative is pretty easy to setup</p><br />
<pre class="html"><code><body>
<div id="app"></div>
</body></code></pre><br />
<pre class="js"><code>import Dative from "dativejs";
Dative.config.slient = false; // it enables warnings
var app = new Dative({
el: "#app", // target for the instance, Can be either an id or a class or a node
// OR
target: "#app",
template: "", // template for the instance
// OR
template: function(){},
data: {}, // reactive object
// OR
data: function(){ return {} },
methods: {}, // event listeners
store: store, // attaching the dytejs store
computed: {}, // combining/merging two or more datas
mounted: function(){}, // function invoked when the dom has mounted
created: function(){}, // function invoked when the instance is created
update: function({ data }){}, // function invoked when theirs any changes
directives: {} // creating custom directives
})
app.render()</code></pre><br />
<hr>
<br>
<h1 class="text-2xl" id="reactive">REACTIVITY</h1><br />
<pre class="js"><code>import Dative from "dativejs"; // gzip (2.99KB)
Dative.config.slient = false; // it enables warnings
var app = new Dative({
el: "#app",
data: ()=>({
count: 0
}),
template: function(){
return `
<h1>{{ count }}</h1>
<button dv-on:click="increase">Increase</button>
`
},
methods:{
increase(){
this.data.count++
}
}
})
app.render()</code></pre><br />
<hr>
<br>
<h1 class="text-2xl" id="directives">ELEMENT DIRECTIVES</h1><br />
<p>As well as attributes, elements can have directives, which control the element's behaviour in some way.</p>
<br />
<h3 class="font-bold text-3xl">dv-on:eventname</h3><br />
<pre><code>dv-on:eventname="handler"</code></pre><br />
<p>Use the dv-on: directive to listen to DOM events.</p><br />
<p>The @eventname and dv-on="eventname: function" are the same with the dv-on:eventname</p>
<h3 class="font-bold text-3xl">dv-ref</h3><br />
<pre class="js"><code>template: function(){
return `
<input type="text" dv-ref="input">
`
}</code></pre><br />
<p>Use the dv-ref directive to reference an element</p><br />
<h3 class="font-bold text-3xl">dv-html</h3><br />
<pre class="js"><code>import Dative from "dativejs"; // gzip (2.99KB)
Dative.config.slient = false; // it enables warnings
var app = new Dative({
el: "#app",
data: ()=>({
html_content: "<h2>Hello World </h2>"
}),
template: function(){
return `
<div dv-html="html_content"></div>
`
}
})
app.render()</code></pre><br />
<p>Use the dv-html directive to insert content from the data to innerHTML of an element</p><br />
<h3 class="font-bold text-3xl">dv-text</h3><br />
<pre class="js"><code>import Dative from "dativejs"; // gzip (2.99KB)
Dative.config.slient = false; // it enables warnings
var app = new Dative({
el: "#app",
data: ()=>({
text_content: "Hello World"
}),
template: function(){
return `
<div dv-text="text_content"></div>
`
}
})
app.render()</code></pre><br />
<p>Use the dv-text directive to insert content from the data to textContent of an element</p><br />
<h3 class="font-bold text-3xl">dv-show</h3><br />
<pre class="js"><code>import Dative from "dativejs"; // gzip (2.99KB)
Dative.config.slient = false; // it enables warnings
var app = new Dative({
el: "#app",
data: ()=>({
show: false
}),
template: function(){
return `
<div dv-show="show">
<h1>I'll not display</h1>
</div>
`
}
})
app.render()</code></pre><br />
<p>Use the dv-show directive to toggle the element's display CSS property based on the truthy-ness of the given expression value</p><br />
<h3 class="font-bold text-3xl">dv-if</h3><br />
<pre class="js"><code>import Dative from "dativejs"; // gzip (2.99KB)
Dative.config.slient = false; // it enables warnings
var app = new Dative({
el: "#app",
data: ()=>({
show: false
}),
template: function(){
return `
<div dv-if="show">
<h1>I'll be hidden</h1>
</div>
`
}
})
app.render()</code></pre><br />
<p>Use the dv-if directive to conditionally render the template based on the truthy-ness of the given expression value</p><br />
<h3 class="font-bold text-3xl">:style</h3><br />
<pre class="js"><code>import Dative from "dativejs"; // gzip (2.99KB)
Dative.config.slient = false; // it enables warnings
var app = new Dative({
el: "#app",
data: ()=>({
styles:{
background: "red",
fontSize: 30,
'text-align': 'center'
}
}),
template: function(){
return `
<div :style="styles">
<h1>I'll have a red background</h1>
</div>
`
}
})
app.render()</code></pre><br />
<p>Use the :style directive to pass an object or an array to dynamically update styles. You can use either camelCase or kebab-case (use quotes with kebab-case) for the CSS property names</p><br />
<h3 class="font-bold text-3xl">:class</h3><br />
<pre class="js"><code>import Dative from "dativejs"; // gzip (2.99KB)
Dative.config.slient = false; // it enables warnings
var app = new Dative({
el: "#app",
data: ()=>({
active_class:{
active: true
}
}),
template: function(){
return `
<div :class="active_class">
<h1>my parent tag will have a class name of active</h1>
</div>
`
}
})
app.render()</code></pre><br />
<p>Use the :class directive to pass an object or an array to dynamically update classes</p><br />
<h3 class="font-bold text-3xl">:<attribute></h3><br />
<pre class="js"><code>import Dative from "dativejs"; // gzip (2.99KB)
Dative.config.slient = false; // it enables warnings
var app = new Dative({
el: "#app",
data: ()=>({
href: '/'
}),
template: function(){
return `
<div>
<a :href="href">Home</a>
</div>
`
}
})
app.render()</code></pre><br />
<p>Use the :<attribute> directive to dynamically render contents from data to the element</p><br />
<h3 class="font-bold text-3xl">dv-bind:<attribute></h3><br />
<pre class="js"><code>import Dative from "dativejs"; // gzip (2.99KB)
Dative.config.slient = false; // it enables warnings
var app = new Dative({
el: "#app",
data: ()=>({
href: '/'
}),
template: function(){
return `
<div>
<a dv-bind:href="href">Home</a>
</div>
`
}
})
app.render()</code></pre><br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5442324990787763"
crossorigin="anonymous"></script>
<!-- new ads -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-5442324990787763"
data-ad-slot="1918194121"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The dv-bind:<attribute> directive does exactly the same thing the :<attribute> does.Its the long form for the :<attribute></p><br />
<hr />
<br />
<h2 class="text-2xl font-bold" id="create-your-own-custom-directive">Create Your own Custom Directives</h2><br />
<h4 class="text-xl">Without Binds</h4><br />
<pre class="js"><code>import Dative from "dativejs"; // gzip (2.99KB)
Dative.config.slient = false; // it enables warnings
var app = new Dative({
el: "#app",
template: function(){
return `
<div>
<h2 dv-rainbow>Hello DativeJs</h2>
</div>
`
},
directives:{
rainbow: function(el,{ bind,name }){
// el is the target element
el.style.color = `#${Math.random().toString().slice(2,8)}`
}
}
})
app.render()</code></pre><br />
<h4 class="text-xl">With Binds</h4><br />
<pre class="js"><code>import Dative from "dativejs"; // gzip (2.99KB)
Dative.config.slient = false; // it enables warnings
var app = new Dative({
el: "#app",
template: function(){
return `
<div>
<h2 dv-color="green">Hello DativeJs</h2>
</div>
`
},
directives:{
color: function(el,{ bind,name }){
// el is the target element
// bind.value is the directives value
el.style.color = bind.value
}
}
})
app.render()</code></pre><br />
<h4 class="text-xl">With Binds argument</h4><br />
<pre class="js"><code>import Dative from "dativejs"; // gzip (2.99KB)
Dative.config.slient = false; // it enables warnings
var app = new Dative({
el: "#app",
template: function(){
return `
<div>
<h2 dv-color:background="green">Hello DativeJs</h2>
</div>
`
},
directives:{
color: function(el,{ bind,name }){
// el is the target element
// bind.value is the directives value
// bind.args is the text that's after the :
if(bind.args === "background"){
el.style.background = bind.value
}else{
el.style.color = bind.value
}
}
}
})
app.render()</code></pre><br />
<hr>
<br>
<h2 class="text-2xl font-bold" id="computed">COMPUTED</h2><br />
<p>Computed properties allow us to define a property that is used the same way as data, but can also have some custom logic that is cached based on its dependencies</p><br />
<pre class="js"><code>computed:{
fullname: function(){
return this.firstname + ' ' + this.lastname
}
}</code></pre><br>
<hr>
<br>
<h2 class="text-2xl font-bold" id="state-management">STATE MANAGEMENT</h2><br />
<p>It is often overlooked that the source of truth in Dative applications is the raw data object - a Dative instance only proxies access to it. Therefore, if you have a piece of state that should be shared by multiple instances, you can share it by identity:</p><br />
<pre class="js"><code>import Dative,{ reactive } from "dativejs"; // gzip (2.99KB)
Dative.config.slient = false; // it enables warnings
var SourceofTruth = reactive({
name: "dative"
})
var vm = new Dative({
data: SourceofTruth
})
var app = new Dative({
data: SourceofTruth
})
// it should update the two applications
SourceofTruth.name = "Tobithedev";</code></pre><br />
<h2 class="text-2xl font-bold" id="set">Set</h2><br />
<p>We use the <code>set</code> function to update the data property</p><br />
<pre class="js"><code>import Dative from "dativejs"; // gzip (2.99KB)
Dative.config.slient = false; // it enables warnings
var app = new Dative({
el: "#app",
data:()=>({
username: 'James'
}),
template: function(){
return `
<div>
<h2>Hello {{ username }}</h2>
</div>
`
},
mounted(){
this.set({
username: "Tobithedev"
})
}
})
app.render()</code></pre><br />
<h2 class="text-2xl font-bold" id="set">Set</h2><br />
<p>We use the <code>get</code> function to get the data property</p><br />
<pre class="js"><code>import Dative from "dativejs"; // gzip (2.99KB)
Dative.config.slient = false; // it enables warnings
var app = new Dative({
el: "#app",
data:()=>({
username: 'Tobithedev'
}),
template: function(){
return `
<div>
<h2>Hello {{ username }}</h2>
</div>
`
},
mounted(){
console.log(this.get().username) // => Tobithedev
}
})
app.render()</code></pre><br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5442324990787763"
crossorigin="anonymous"></script>
<!-- new ads -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-5442324990787763"
data-ad-slot="1918194121"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
</body>
<script src="src/highlight.min.js"></script>
<script src="main.js"></script>
<script>
hljs.initHighlightingOnLoad();
function sideopen(){
if($('#sidebar').style.width == '0px'){
$('#sidebar').style.width = '15rem'
}else{
$('#sidebar').style.width = '0px'
}
}
</script>
</html>