fomkin / korolev Goto Github PK
View Code? Open in Web Editor NEWSingle Page Applications running on the server side.
License: Apache License 2.0
Single Page Applications running on the server side.
License: Apache License 2.0
Downloaded https://repo1.maven.org/maven2/com/lihaoyi/utest_2.11/0.4.4/utest_2.11-0.4.4.jar
[info] Compiling 1 Scala source to C:\home\projects\git\korolev\async.jvm\target\scala-2.11\classes...
[info] Compiling 2 Scala sources to C:\home\projects\git\korolev\vdom.jvm\target\scala-2.11\classes...
[info] Compiling 5 Scala sources to C:\home\projects\git\korolev\bridge.jvm\target\scala-2.11\classes...
[info] Compiling 8 Scala sources to C:\home\projects\git\korolev\korolev.jvm\target\scala-2.11\classes...
[info] Compiling 8 Scala sources to C:\home\projects\git\korolev\server\target\scala-2.11\classes...
[info] Compiling 6 Scala sources to C:\home\projects\git\korolev\server-blaze\target\scala-2.11\classes...
java.lang.RuntimeException: No main class detected.
at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last simpleExample/compile:run for the full output.
[error] (simpleExample/compile:run) No main class detected.
[error] Total time: 28 s, completed Feb 18, 2017 10:53:34 AM
C:\home\projects\git\korolev>sbt simpleExample/run
Session has no information about static router input.
'span(
if (cond) 'strong("Hello")
else "Hello"
)
'div(
'border @= "1px solid red"
'backgroundColor @= "black",
"Hello world"
)
Currently we bound on http4s. It should become a module named http4s with Task
as IO monad. KorlevServerHttp4s should generate rout, not runnable.
val application = Korolev(TheState.empty)
.bindHttp(port, host)
.render(renderPartialFunction)
.stateStorage(stateStorageInstance)
FormData allows to send HTML forms asynchronously. Idea is to send forms via HTTP[S] and notify about progress via WebSocket.
FromData
uploading using XMLHttpRequest.send
val myForm = elementId
'form(
myForm,
eventWithAccess('submit) { access =>
access
.downloadFormData(myForm)
.onProgress { (loaded, total) =>
// transition …
}
.start
.map { formData =>
val picture = data.file("picture") // Array[Byte]
val title = data.text("title") // String
// transition ...
}
},
'input('name = "title", 'type /= "text"),
'input('name = "picture", 'type /= "file"),
'input('type /= "button", "Submit")
)
multipart/form-data
codecIdea is to serve some resource files like css or png directly from class path.
The diff algorithm works fine when appending:
val a = 'div (
'h2 /= "", 'h1 /= "", 'h2 /= "", 'h1 /= "", 'h2 /= "", 'h1 /= "", 'h2 /= "")
val b = 'div (
'h2 /= "", 'h1 /= "", 'h2 /= "", 'h1 /= "", 'h2 /= "", 'h1 /= "", 'h2 /= "",
'h1 /= "new")
VDom.changes(a, b) == List(SetAttr(0,"h1","new",false))
But seams to preform poorly when prepending:
val a = 'div (
'h2 /= "", 'h1 /= "", 'h2 /= "", 'h1 /= "", 'h2 /= "", 'h1 /= "", 'h2 /= "")
val b = 'div (
'h1 /= "new",
'h2 /= "", 'h1 /= "", 'h2 /= "", 'h1 /= "", 'h2 /= "", 'h1 /= "", 'h2 /= "")
VDom.changes(a, b) == List(
SetAttr(0,"h2","",false),
RemoveAttr(0,"h2",""false),
SetAttr(0,"h1","",false),
RemoveAttr(0,"h1",""false),
SetAttr(0,"h2","",false),
RemoveAttr(0,"h2",""false),
SetAttr(0,"h1","",false),
RemoveAttr(0,"h1",""false),
SetAttr(0,"h2","",false),
RemoveAttr(0,"h2",""false),
SetAttr(0,"h1","",false),
RemoveAttr(0,"h1",""false),
SetAttr(0,"h2","",false),
RemoveAttr(0,"h2",""false),
SetAttr(0,"h1","new",false)
)
FWIW the kivi implementation seams to hande these cases while remaining reasonably simple
Do some JavaScript when DOM element added/removed from from virtual DOM
routingExample[ERROR] bridge.JSAccess$JSSideException: [object Object].ListenEvent(clic
routingExample[ERROR] at bridge.JSAccess.resolvePromise(JSAccess.scala:141)
routingExample[ERROR] at korolev.server.JsonQueuedJsAccess.receive(JsonQueuedJsAccess.scala:95)
routingExample[ERROR] at korolev.server.package$$anonfun$1.$anonfun$applyOrElse$9(package.scala:114)
routingExample[ERROR] at korolev.server.package$$anonfun$1.$anonfun$applyOrElse$9$adapted(package.scala:114)
routingExample[ERROR] at korolev.blazeServer.package$$anon$1.onMessage(package.scala:81)
routingExample[ERROR] at korolev.blazeServer.WebSocketStage.$anonfun$_wsLoop$1(WebSocketStage.scala:28)
routingExample[ERROR] at korolev.blazeServer.WebSocketStage.$anonfun$_wsLoop$1$adapted(WebSocketStage.scala:24)
routingExample[ERROR] at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
routingExample[ERROR] at org.http4s.blaze.util.Execution$$anon$1.execute(Executor.scala:27)
routingExample[ERROR] at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:68)
routingExample[ERROR] at scala.concurrent.impl.Promise$DefaultPromise.$anonfun$tryComplete$1(Promise.scala:284)
routingExample[ERROR] at scala.concurrent.impl.Promise$DefaultPromise.$anonfun$tryComplete$1$adapted(Promise.scala:284)
routingExample[ERROR] at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:284)
routingExample[ERROR] at scala.concurrent.Promise.trySuccess(Promise.scala:90)
routingExample[ERROR] at scala.concurrent.Promise.trySuccess$(Promise.scala:90)
routingExample[ERROR] at scala.concurrent.impl.Promise$DefaultPromise.trySuccess(Promise.scala:183)
routingExample[ERROR] at org.http4s.blaze.channel.nio2.ByteBufferHead$$anon$3.completed(ByteBufferHead.scala:100)
routingExample[ERROR] at org.http4s.blaze.channel.nio2.ByteBufferHead$$anon$3.completed(ByteBufferHead.scala:87)
After KorolevAccess
removal access to Dux
was disallowed. We need turn them back.
Now we have no way to identify user inside render, but we should have it.
Connection opened.
batch,0,getAndSaveAs,@link:global,Korolev,@Korolev,1,registerCallback,^cb0
0,getAndSaveAs,@link:global,Korolev,@Korolev
0,true,@obj:@Korolev
1,registerCallback,^cb0
1,true,@obj:^cb0
batch,2,registerCallback,^cb1
2,registerCallback,^cb1
2,true,@obj:^cb1
batch,3,call,@link:@Korolev,SetRenderNum,0
3,call,@link:@Korolev,SetRenderNum,0
3,true,@unit
batch,4,call,@link:@Korolev,RegisterHistoryHandler,@link:^cb0
4,call,@link:@Korolev,RegisterHistoryHandler,@link:^cb0
4,true,@unit
Looks like we need to have session management.
It may be useful when we want to play some basic animation or hide something after timeout.
Global timer (session context)
KorolevServer[Boolean](
...
timers = {
case true =>
delay(2 seconds) {
case _ => false
}
}
)
Inside view
render = {
case state =>
'div(
h1("Title"),
if (!state) <>
else 'div(
"Something we want to hide",
delay(2 seconds) {
case _ => false
}
)
)
}
When a http request comes in it goes through korolev/server/package.scala:
def renderStatic(request: Request): F[Response] = {
If the file is a javascript static resource then it returns
<!DOCTYPE html><html ><head ><script > then the javascript code -
resulting in a error
Now access
objects make render functions impure. This disallow to enable memorization for render functions.
Allow to add static js and css urls when defining Korolev.
korolev-server-blaze-fs2-scalaz
korolev-server-blaze-fs2-cats
korolev-server-blaze
We are using Artillery framework for load testing. I launched basic quick load test for routingExample artillery quick --duration 20 --rate 5 -n 5 http://localhost:8181
,
I got that big stack trace (I recduced it a little) :
[ForkJoinPool-1-worker-1] ERROR org.http4s.blaze.pipeline.Stage - Error during 'handleRequest' of HttpServerStage
scala.MatchError: [Ljava.lang.String;@623a6f (of class [Ljava.lang.String;)
[ForkJoinPool-1-worker-1] INFO org.http4s.blaze.pipeline.Stage - Shutting down HttpPipeline at Tue Jan 31 10:48:06 EET 2017
[ForkJoinPool-1-worker-1] ERROR org.http4s.blaze.pipeline.Stage - NIO2 channel closed with an unexpected error
scala.MatchError: [Ljava.lang.String;@623a6f (of class [Ljava.lang.String;)
It seems like there are some problems in cookies handling.
A lot of people say that unsecure Korolev pages don't works because corporative secure policy forbid WebSockets (or proxy doesn't support them). We need to have SSL support.
What is Router?
case class Router[F[_]: Async, S](
from: S => Path,
to: (DeviceId, Path) => F[S]
)
Router should:
State
to the Path
. For example we have state case class State(blogId: String @@ Blog, articleId: String @@ Article, text: String)
. So path is /blogs/${state.blogId}/articles/${state.articleId}
.Path
to the State
. We should remember that state state generation can produce side effects like DB access.What we have
import korolev.Korolev.Render
import korolev.EventResult
What we need
import korolev._
deviceId
. If it absent we have to set it using cookie.deviceId
to State
resolver. It is state generator for new sessions.Allow to plug metric trackers. What should be tracked:
If DOM was updated, events tail of events should be dropped.
It would be cool to support Java EE application containers.
Korolev requires cookie to work. EU Cookie Law requires warn user about that. It can be done by programmer (just add closable panel to top of page) or Korolev, before the deviceId will be set.
No we able listen only mousedown
, mouseup
, click
and submit
. We need to be able to listen any event.
When people want to use Scalaz or Cats they are don't want to use Future
from standard library. I think we have to write our own monad like type class. Good namings: Async
, Deferred
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.