cradova 3.3.8 → 3.3.9

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 CHANGED
@@ -186,7 +186,7 @@ APPENDIX: How to apply the Apache License to your work.
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright 2022 friday candour
189
+ Copyright 2022 `friday candour`
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  <h1 align="center">Cradova</h1>
8
8
 
9
9
  <p align="center">
10
- Cradova is a JavaScript framework for building Single Page Applications and PWAs.
10
+ Build Powerful Web Apps with Ease
11
11
  <br/>
12
12
  <br/>
13
13
  <a href="https://github.com/uiedbook/cradova#examples"><strong>Explore the 🎙️ docs »</strong></a>
@@ -27,25 +27,22 @@
27
27
  [![npm Downloads](https://img.shields.io/npm/dm/cradova.svg)](https://www.npmjs.com/package/cradova)
28
28
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/cradova/cradova.js/blob/next/contributing.md)![Forks](https://img.shields.io/github/forks/uiedbook/cradova?style=social) ![Stargazers](https://img.shields.io/github/stars/uiedbook/cradova?style=social)
29
29
 
30
- ## 2024 - What's New? Ref methods!
30
+ # Cradova is 3
31
31
 
32
32
  ```js
33
- type dataType = { year: string, age: string };
34
-
35
- const Header =
36
- new Ref() <
37
- dataType >
38
- function (data = { year: "2023", age: "2" }) {
39
- return header(h1("Cradova is " + data.age + " yrs old in " + data.year));
40
- };
41
-
42
- Header.define("increase", function (isNewYear) {
43
- if (isNewYear) {
44
- this.updateState({ year: "2024", age: "3" });
45
- }
33
+ const Cradova = new Comp(function () {
34
+ const [year, setYear] = useState(3, this);
35
+
36
+ return h1("Cradova is " + year + " yrs old in ", {
37
+ onclick() {
38
+ setYear((lastYear) => {
39
+ return lastYear + 1;
40
+ });
41
+ },
42
+ });
46
43
  });
47
- document.body.appendChild(Header.render());
48
- Header.methods.increase(true);
44
+
45
+ document.body.appendChild(Cradova.render());
49
46
  ```
50
47
 
51
48
  ## 2023 - What's New? Conditionals!
@@ -91,24 +88,20 @@ document.body.append(html, whatsAllowed({ age: 26 }));
91
88
 
92
89
  Cradova is a web development framework for building Single Page Applications and PWAs.
93
90
 
94
- It's a fast and simple framework, it provides an easy to use state management and router system.
95
-
96
91
  Cradova follows the [VJS specification](https://github.com/uiedbook/cradova/blob/main/VJS_spec/specification.md)
97
92
 
98
93
  ## What's the benefit?
99
94
 
100
- Cradova is aimed to be fast and simple with and fewer abstractions and yet easily composable.
95
+ Fast and simple with and fewer abstractions and yet easily composable.
101
96
 
102
97
  Cradova is not built on virtual DOM or diff algorithms.
103
- Instead, State management is done more elegantly with a simple predictive model, simple and easy with all the speed.
98
+ Instead, State management is done in a way that is simple, easy and fast.
104
99
 
105
100
  ## Is this a big benefit?
106
101
 
107
102
  Undoubtedly, this provides a significant advantage.
108
103
 
109
- Cradova has already been utilized in multiple production projects, and we will continuously update this page to showcase our advancements as we keep improving.
110
-
111
- [current version changes](https://github.com/uiedbook/cradova/blob/main/CHANGELOG.md#v330)
104
+ [current version changes](https://github.com/uiedbook/cradova/blob/main/CHANGELOG.md#v400)
112
105
 
113
106
  ## Installation
114
107
 
@@ -129,7 +122,7 @@ npm i cradova
129
122
 
130
123
  ## Examples
131
124
 
132
- Many aspects of Cradova are not reflected in the following example. More functionality will be entailed in future docs.
125
+ Some aspects of Cradova are not reflected in the following example. More functionality will be entailed in future docs.
133
126
 
134
127
  ## A basic component in Cradova:
135
128
 
@@ -152,48 +145,32 @@ document.body.append(html);
152
145
 
153
146
  ## Basic Samples:
154
147
 
155
- this a collection of basic examples that can give you some ideas
148
+ This a collection of basic examples that can give you some ideas
156
149
 
157
150
  ```js
158
- import _, { button, createSignal, Ref, reference, h1, br, div } from "cradova";
159
-
151
+ import {
152
+ button,
153
+ createSignal,
154
+ Comp,
155
+ reference,
156
+ h1,
157
+ br,
158
+ div,
159
+ useRef,
160
+ } from "cradova";
160
161
 
161
- const count = new Ref(function () {
162
+ const count = new Comp(function () {
162
163
  const [count, setCounter] = useState(0, this);
163
164
  setTimeout(() => {
164
165
  setCounter(count + 1);
165
166
  }, 1000);
166
- return h1(" the current count is = " + count);
167
+ return h1(" count: " + count);
167
168
  });
168
169
 
169
- function counter() {
170
- let num = 0;
171
- return _("h1| 0", {
172
- onclick() {
173
- num++;
174
- this.innerText = num;
175
- },
176
- });
177
- }
178
-
179
- // Another example with data- attribute
180
-
181
- function dataCounter() {
182
- return _("h1| 0", {
183
- "data-num": "0",
184
- onclick() {
185
- const num = this.getAttribute("data-num") * 1 + 1;
186
- this.setAttribute("data-num", num });
187
- this.innerText = num;
188
- },
189
- });
190
- }
191
-
192
170
  // hello message
193
171
 
194
172
  function HelloMessage() {
195
- return div({
196
- text: "Click to get a greeting",
173
+ return div("Click to get a greeting", {
197
174
  onclick() {
198
175
  const name = prompt("what are your names");
199
176
  this.innerText = name ? "hello " + name : "Click to get a greeting";
@@ -203,15 +180,16 @@ function HelloMessage() {
203
180
 
204
181
  // using CradovaRef
205
182
 
206
- const nameRef = new Ref(function (name) {
207
- const self = this;
208
- return _("div.foo#bar", {
209
- text: name
210
- ? "hello " + (name || " user 2")
211
- : "Click to get a second greeting",
183
+ const nameRef = new Comp(function () {
184
+ const [name, setName] = (useState < string) | (undefined > (undefined, this));
185
+ return div(name ? "hello " + name : "Click to get a second greeting", {
212
186
  onclick() {
213
187
  const name = prompt();
214
- self.updateState(name);
188
+ if (name) {
189
+ setName(name);
190
+ } else {
191
+ alert("Please provide a valid name");
192
+ }
215
193
  },
216
194
  });
217
195
  });
@@ -219,21 +197,20 @@ const nameRef = new Ref(function (name) {
219
197
  // reference (not state)
220
198
 
221
199
  function typingExample() {
222
- const re = new reference();
223
- return _(
224
- "div",
200
+ const ref = useRef();
201
+ return div(
225
202
  input({
226
203
  oninput() {
227
- re.text.innerText = this.value;
204
+ ref.current("text").innerText = this.value;
228
205
  },
229
206
  placeholder: "typing simulation",
230
207
  }),
231
- p(" no thing typed yet!", { reference: re.bindAs("text") })
208
+ p(" no thing typed yet!", { reference: ref.bindAs("text") })
232
209
  );
233
210
  }
234
211
 
235
212
  function App() {
236
- return div(count, counter, dataCounter, HelloMessage, br, nameRef);
213
+ return div(count, typingExample, HelloMessage, nameRef);
237
214
  }
238
215
 
239
216
  document.body.append(App());
@@ -244,21 +221,18 @@ document.body.append(App());
244
221
  Let's see a simple TodoList example
245
222
 
246
223
  ```js
247
- import _, {
248
- // tags
249
- div,
224
+ import {
250
225
  button,
226
+ createSignal,
227
+ useState,
228
+ div,
229
+ input,
251
230
  main,
252
231
  p,
253
- input,
254
- // allows you to create powerful data stores
255
- createSignal,
256
- // dom ref
257
- useRef(),
258
- // dynamic component class
259
- Ref,
260
- css,
261
- } from "cradova";
232
+ Comp,
233
+ h1,
234
+ useRef,
235
+ } from "../dist/index.js";
262
236
 
263
237
  function TodoList() {
264
238
  // can be used to hold multiple references
@@ -267,7 +241,7 @@ function TodoList() {
267
241
  // creating a store
268
242
  const todoStore = new createSignal([
269
243
  "take bath",
270
- "code code code",
244
+ "code coded",
271
245
  "take a break",
272
246
  ]);
273
247
 
@@ -282,12 +256,12 @@ function TodoList() {
282
256
  this.set(this.value);
283
257
  });
284
258
 
285
- // bind Ref to Signal
259
+ // bind Comp to Signal
286
260
  todoStore.bindRef(todoList);
287
261
 
288
262
  // markup
289
263
  return main(
290
- _`|Todo List`,
264
+ p(`|Todo List`),
291
265
  div(
292
266
  input({
293
267
  placeholder: "type in todo",
@@ -295,8 +269,11 @@ function TodoList() {
295
269
  }),
296
270
  button("Add todo", {
297
271
  onclick() {
298
- todoStore.fireAction("add-todo", referenceSet.todoInput.value);
299
- referenceSet.todoInput.value = "";
272
+ todoStore.fireAction(
273
+ "add-todo",
274
+ referenceSet.current("todoInput").value
275
+ );
276
+ referenceSet.current("todoInput").value = "";
300
277
  },
301
278
  })
302
279
  ),
@@ -304,7 +281,7 @@ function TodoList() {
304
281
  );
305
282
  }
306
283
 
307
- const todoList = new Ref(function () {
284
+ const todoList = new Comp(function () {
308
285
  const self = this;
309
286
  return div(
310
287
  self.Signal.value.map((item) =>
@@ -317,82 +294,64 @@ const todoList = new Ref(function () {
317
294
  )
318
295
  );
319
296
  });
320
-
321
297
  document.body.appendChild(TodoList());
322
-
323
- css`
324
- body {
325
- box-sizing: border-box;
326
- display: flex;
327
- }
328
- main {
329
- margin: auto;
330
- }
331
- main > p {
332
- font-size: 2rem;
333
- }
334
- `;
335
298
  ```
336
299
 
337
- ## working with screen and Router:
300
+ ## working with page and Router:
338
301
 
339
- unlike just appending stuff to the DOM,
302
+ Unlike just appending stuff to the DOM,
340
303
  a better to build apps is to use a routing system.
341
304
 
342
305
  Cradova Router is a module that allows you do the following:
343
306
 
344
307
  Create specified routes in you application
345
- help you orchestrate navigation
346
- render a screen on a route
347
- pre-render a screen in the background if you want to.
308
+ help you handle navigation
309
+ render a page on a route
348
310
  listen to Navigation changes
349
- create error boundary at screen level.
350
- persist rendered screens by default
351
- allow parallel screen rendering for every unique route scheme
311
+ create error boundary at page level apart from Comp level.
352
312
 
353
313
  let's try an example.
354
314
 
355
315
  ```js
356
- import _, { Screen, Router } from "cradova";
316
+ import { Page, Router } from "cradova";
357
317
 
358
- // Ref can be used as screens
318
+ // Comp can be used as page template this way
359
319
 
360
- const template = new Ref(function (name) {
361
- // an effect run once after screen renders
320
+ const template = new Comp(function (name) {
321
+ // an effect run once after page renders
362
322
  const self = this;
363
323
  self.effect(() => {
364
324
  const name = new Promise((res) => {
365
325
  res("john doe");
366
326
  });
367
327
  setTimeout(async () => {
368
- self.updateState(await name);
328
+ self.recall(await name);
369
329
  }, 1000);
370
330
  });
371
331
  // effects can be used to make api calls needed for the page
372
- return _("div", name ? ">>>>>>>> Hello " + name : " loading...");
332
+ return div(name ? ">>>>>>>> Hello " + name : " loading...");
373
333
  });
374
334
 
375
- const home = new Screen({
335
+ const home = new Page({
376
336
  name: "home page", // page title
377
- template,
337
+ template: () => div(template),
378
338
  });
379
339
 
380
340
  // in your routes.ts file
381
341
  Router.BrowserRoutes({
342
+ // Ways to use paths and Pages
343
+ "*": home,
382
344
  "/home": home,
345
+ "/home?": home,
346
+ "/home/:name": home,
347
+ // will be lazy loaded
383
348
  "/lazy-loaded-home": async () => await import("./home"),
384
349
  });
385
350
  // creates these routes
386
351
 
387
- Router.packageScreen("/home", data);
388
- // get the page ready in the background
389
-
390
352
  Router.navigate("/home", data);
391
353
  // navigates to that page
392
354
 
393
- Router.getParams();
394
- // get route params for this current page
395
-
396
355
  Router.onPageEvent((lastRoute, newRoute) => {
397
356
  console.log(lastRoute, newRoute);
398
357
  });
@@ -417,41 +376,34 @@ so if you want to use your own mount point then create a div with data-wrapper="
417
376
 
418
377
  ---
419
378
 
420
- More info on Cradova screens
379
+ More info on Cradova pages
421
380
 
422
381
  ---
423
382
 
424
- screens are rendered once by default to hack
425
- responsiveness making your app work fast as user navigates.
426
-
427
- this behavior can be override
428
- by passing
429
- persist: false
430
- in the constructor
431
-
432
- Cradova screens has
383
+ Cradova pages has
433
384
  onActivate() and
434
385
  onDeactivate() methods which is also available in the
435
386
  component function on the this variable bound to it.
436
387
 
437
388
  this allow you manage rendering
438
- circle for each screen in your app
389
+ circle for each page in your app
439
390
 
440
391
  ---
441
392
 
442
- More info on Cradova Ref
393
+ More info on Cradova Comp
443
394
 
444
395
  ---
445
396
 
446
- Cradova Ref is a dynamic component class, which ships simple abstractions like:
397
+ Cradova Comp is a dynamic component class, which ships simple abstractions like:
447
398
 
448
- - Effects
449
- - stash
399
+ - recall
400
+ - useEffect
401
+ - useState
402
+ - useRef
450
403
  - preRender
451
- - updateState
452
404
 
453
405
  these behaviors allow you manage rendering
454
- circle for refs in your app
406
+ circle for Comps in your app
455
407
 
456
408
  ---
457
409
 
@@ -465,12 +417,12 @@ with ability to:
465
417
 
466
418
  - create store
467
419
  - create actions and fire them
468
- - bind a Ref
420
+ - bind a Comp
469
421
  - listen to changes
470
422
  - persist changes to localStorage
471
- - update a CradovaRef and bindings automatically
423
+ - update a Comp and bindings automatically
472
424
 
473
- With these simple and easy abstractions, you can use datastores with powerful convenience.
425
+ With these simple and easy abstractions, you can write datastores with so much convenience.
474
426
 
475
427
  ## Documentation
476
428
 
@@ -478,7 +430,7 @@ At the moment, we're in the process of creating a documentation website for Crad
478
430
 
479
431
  ## Getting Help
480
432
 
481
- To get further insights and help on Cradova, visit our [Discord](https://discord.gg/b7fvMg38) and [Telegram](https://t.me/uiedbookHQ) Community Chats.
433
+ To get further insights and help on Cradova, visit the [Discord](https://discord.gg/b7fvMg38) and [Telegram](https://t.me/uiedbookHQ) Community Chats.
482
434
 
483
435
  ## Contributing
484
436
 
@@ -503,8 +455,6 @@ We are currently working to [set](https://github.com/uiedbook/cradova/blob/main/
503
455
 
504
456
  Opensourced And Free.
505
457
 
506
- Uiedbook is an open source team of web focused engineers, Our vision is to make the web better, improving and innovating infrastructures for a better web experience.
507
-
508
458
  Join Us on [telegram](https://t.me/UiedbookHQ).
509
459
 
510
460
  ### Contribution and License Agreement
@@ -515,7 +465,12 @@ If you contribute code to this project, you are implicitly allowing your code to
515
465
 
516
466
  Your Support is a good force for change anytime you do it, you can ensure Our projects, growth, Cradova, Cradova, JetPath etc, growth and improvement by making a re-occuring or fixed sponsorship
517
467
  to [github sponsors](https://github.com/sponsors/FridayCandour):
518
- or crypto using
519
- etheruen: `0xD7DDD4312A4e514751A582AF725238C7E6dF206c`,
520
- Bitcoin: `bc1q5548kdanwyd3y07nyjjzt5zkdxqec4nqqrd760` or
521
- LTC: `ltc1qgqn6nqq6x555rpj3pw847402aw6kw7a25dc29w`.
468
+
469
+ Support via cryptos -
470
+
471
+ - BTC: `bc1q228fnx44ha9y5lvtku70pjgaeh2jj3f867nwye`
472
+ - ETH: `0xd067560fDed3B1f3244d460d5E3011BC42C4E5d7`
473
+ - LTC: `ltc1quvc04rpmsurvss6ll54fvdgyh95p5kf74wppa6`
474
+ - TRX: `THag6WuG4EoiB911ce9ELgN3p7DibtS6vP`
475
+
476
+ Build Powerful ⚡ Web Apps with Ease.
package/dist/index.d.ts CHANGED
@@ -1,12 +1,3 @@
1
- /*! *****************************************************************************
2
- Copyright 2022 Friday Candour. All rights reserved.
3
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4
- this file except in compliance with the License. You may obtain a copy of the
5
- License at http://www.apache.org/licenses/LICENSE-2.0
6
-
7
- See the Apache Version 2.0 License for specific language governing permissions
8
- and limitations under the License.
9
- ********************************************************************************/
10
1
  export * from "./primitives/classes";
11
2
  export * from "./primitives/functions";
12
3
  export * from "./primitives/dom-objects";