Comments (15)
@itsumura-h i updated the links in my original comment to the corresponding files in those 2 projects.
You'll be switching between the hash part of the url on each redraw of the virtual dom. All your variables should be kept in a global scope and you should mutate accordingly. This is not the most documented framework for reactive apps but it can be a good match for writing apps in only one language (nim).
from karax.
Here is how I've done it in the Nim forum: https://github.com/nim-lang/nimforum/blob/master/src/frontend/forum.nim#L80
from karax.
Again, let me know if you approve and I can create a formal PR, I'm treating this more as an "RFC" issue.
Alright, approved.
from karax.
The only thing that Jester is being used for is for parsing a route and extracting information in the route.
then maybe that API can be added to stdlib to avoid karax depending on jester?
(and jester can reuse too with when (NimVersion, ...) >= 1.5.1): useStdlib else: redefine
, but that's optional)
from karax.
The point is not to avoid "bloat" or to introduce "code duplication". The point is that I like to iterate over the routing DSL design without concern about how e.g. Jester does it.
from karax.
Check example: https://github.com/pragmagic/karax/blob/master/examples/todoapp/todoapp.nim#L120
If you need variables in the routing you'll need to implement something like this:
https://github.com/dom96/jester/blob/master/jester/patterns.nim#L15
from karax.
Check example: https://github.com/pragmagic/karax/blob/master/examples/todoapp/todoapp.nim#L144
If you need variables in the routing you'll need to implement something like this:
https://github.com/dom96/jester/blob/master/jester/private/patterns.nim
I can't understand how to do...
Can anybody show me how to use variables in the routing more specific?
from karax.
I recently brought this up on the Nim Discord, but should (better) routing be included as a part of Karax, similar to Kajax? By better, I mean something very similar to the way Nim forum does it, but with a bit more syntactic sugar like Jester. In https://forum.nim-lang.org/t/4991#31305 @dom96 brought up moving the forum routing code to karax.
My suggestion would be something like this/Jester:
route "/@id":
renderThreadList(getLoggedInUser(), some(@"id".parseInt))
Along with a function that could be used to directly change the view, such as router.visit("/5")
or something similar.
from karax.
I'm pretty much out of frontend development, sorry, I don't have an opinion. But you can create a PR and I'll have a look.
from karax.
I tried doing something like what I said here:
https://github.com/ajusa/kautil/blob/master/karoute.nim#L36
Only possible issue is that it relies on jester for the route parsing. If you think that is okay, I can polish it up and create a PR for karoute.
from karax.
Meh... Parsing is a finger excercise... The stdlib has strscans for it.
from karax.
While I mostly agree with you, I also don't want to basically copy paste/rewrite the routing handling that Jester already does. Code duplication is almost never a good sign.
Plus this only imports one module within Jester, so it wouldn't be compiling all of Jester anyway. It shouldn't add bloat to Karax (well no more than the Nim Forums, since it also uses the jester/patterns implementation).
from karax.
Routing logic should be in a separate package IMO. Pretty sure even React does it this way. But yes, depending on Jester here is the right way to do it: it means that you can easily reuse the router for both.
The dream is to have something eventually that automagically connects Karax and Jester by just one route spec
from karax.
Well, the routing DSL can be pretty easily changed without worrying about Jester. The only thing that Jester is being used for is for parsing a route and extracting information in the route. It really is just a glorified string matching function 😄
/asdf/@id?
-> seeing if a URL matches and extracting the variable "id" is all Jester uses. The rest of the code was written by me, for handling creation of routes, the DSL, and making sure that it works for websites by using the #
.
I honestly can't really think of any more complicated patterns that we'd want to allow for the parsing. If do need to do that at some point, then we could fork that bit of code from Jester but I'm not sure of any examples where that might be needed. Hope that clears stuff up! Again, let me know if you approve and I can create a formal PR, I'm treating this more as an "RFC" issue.
from karax.
There are several good options for routing at the moment, from those mentioned above to the recently published nimble packages kroutes and kraut.
I'm going to close this for now. At some point we should consider adding these routing options to the documentation.
Please feel free to re-open and comment if you want to discuss further!
from karax.
Related Issues (20)
- Wrong `app.js` directory (`karun`) HOT 1
- Delay in redrawing dom HOT 6
- buildHtml does not capture closure variables HOT 2
- Broken functionalities when karax used with grammarly or languagetool (and possibly other extensions) HOT 8
- How to run a function on onclick event in a button? HOT 4
- Boolean Attributes in DSL HOT 6
- Event example does not work HOT 8
- Release 1.2.3 HOT 5
- view doesn't update when changing state in setInterval HOT 3
- IndexDefect on array HOT 3
- Karax input text becoming null HOT 1
- Async karax? HOT 3
- Empty content editable raises an error HOT 1
- How to attach and detach a custom a `Node` to the karax dom? HOT 1
- Karax does not update event handlers HOT 4
- stack size exceeded error on js target HOT 1
- `verbitam` content is appended every time it changes HOT 1
- runtime error on redraw in `removeAllEventHandlers` proc HOT 2
- SVG rendering HOT 2
- 1.3.2 has a tag and release, but karax.nimble version still 1.3.1 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from karax.