Giter Site home page Giter Site logo

asta's Introduction

image

Asta NPM version NPM downloads

🎯 Asta is a highly specialized full stack framework for SSR. It has no vdom on the server side and 0 js on the client side. Finally, it gets best QPS and Google scores.

Note this is early Development! It is not recommended to use this for anything serious yet.

  • no VDOM on server, 0 javascript on client.
  • write JSX and react-like syntax.

Run demo

yarn start

Syntax

input:

const addCount = $import('./action.js#addCount')

// state: will run in server and inject to client
export const loader = async (req) => {
	return {
		count: req.query.count,
	}
}

// view: will run in both client and server, but s() in server h() in client
export default ({ count }) => {
	return (
		<main>
			<button onclick={addCount}>{count}</button>
		</main>
	)
}

output:

<main><button $onclick="./action/count.js?mod=addCount">0</button></main>

Compiler

Jointing on server, Resumable on client

// jsx input
const view = ({list}) => <div>{list.map(i=><i>{i}</i>)}</div>
// server output
const view = ({list}) => s.openTag('div')+s.expression(list.map(i=>s.openTag('i')+s.text(i)+s.closeTag('i')))+s.closeTag('div')
// client output
const view = ({list}) => h('div',{children:[list.map(i=>h('i',{children:[i]}))]})

How and why

How is This Different from Next.js, Remix.js, Fresh.js or Other SSR Solutions?

There are two biggest differences.

First, the server side. Asta does not run any VDOM-based framework runtime. It generates the s function through the compiler, which is only used for string splicing. At this point, it is a little like Marko.js.

Second, on the client side, Asta is 0 javascript, and it does not require any hydration. This is a new concept, called Resumable, a little like qwik.js.

So, Asta ≈ Marko + Qwik.

Because there is no Vdom overhead on the server side, Asta can get super high QPS and throughput.

Then because the client side is 0 js, it can continuously get a high Google score, and the score will not decrease with the increase of components.

How is This Different from Qwik.js or Marko.js?

In principle, asta is the sum of them, Asta is a double optimization, but the implementation details are quite different.

At the same time, Asta attempts to migrate Elm's mental model to SSR.

There is only a single state tree, and components are pure functions without states or any overhead.

These helps to completely solve performance problems.

Why not Fre SSR or and other Vdom-based frameworks?

Although JSX of fre can also be optimized at compile time, and the client side can also be selective hydrated, it is important that Fre or other Vdom-based framework components are not completely cost free.

说人话?

Asta 的核心是根治性能问题,已知的 SSR 框架有几个性能瓶颈:

  1. server 端的 vdom 开销,组件开销
  • server 端生成和遍历 vdom 成本是巨大的,Asta 在 server 端没有 vdom,它通过一个特殊的编译器将 jsx 编译成 s 函数,只用来拼接字符串

  • server 端组件的初始化,状态更新,生命周期的开销,也是巨大的,Asta 也有组件,但它的组件是纯函数,也只用来拼接字符串,没有任何私有状态和生命周期,这得益于 Elm 的心智模型,单 state tree,组件是纯函数

  1. client 0 js
  • 一个新兴的概念,叫做 Resumable,client 不再水合,而是将必要的信息序列化到 html 里,然后直接从 html 进行恢复,所有的 js 都根据交互懒加载,这样就可以做到 0 js,0 水合,而且这是 O(1) 的,不会因为业务增长而性能下降

Asta 双重优化,彻底根除 SSR 的性能瓶颈

asta's People

Contributors

aiellochan avatar darrendanielday avatar ha0ran2001 avatar inokawa avatar jiangtao avatar jjangga0214 avatar ryouaki avatar saber2pr avatar shenjunjian avatar sl1673495 avatar solarhell avatar wenzhu-eternal avatar winesu avatar yingpengsha avatar yisar avatar yzydeveloper avatar z9956 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

asta's Issues

你好有api吗

多个store 集合 怎么写啊 就像 多个 Reducer 集合一起

有待实现的feature

大概:
1.封装Provider,使它不用传value
2.增加一个unsubscribe

确定不加的:
1.不加immutable,可以自己加,不需要整合进库
2.不加create-context,不打算兼容低版本

还有啥,求issue呀!

typo

I think you meant destroy not destory?

asta/runtime.js

Lines 42 to 45 in 6d50710

if (data.onDestory) {
events.destory = data.onDestory.bind(this)
delete data.onDestory
}

I noticed you tagged the repo with "angular" and "svelte" - although the description says "subset of Vue".

Will this have precise updates like Svelte? No virtual DOM?

Looks interesting. I'm always curious to see what you come up with. 🙂

加载两次Cannot set property 'state' of undefined

按照官网文档的写法,在组件中引用点击按钮出错

在入口文件绑定了store了
import React from 'react';
import {NavLink} from 'react-router-dom';

import { map } from 'smox';

@Map({
state: ['count'],
mutations: ['add', 'cut'],
actions: ['asyncAdd']
})

export default class Share extends React.Component{
constructor(props) {
super(props);
}
render () {
console.log(this.props); // 这里打印两次
return (


现在是{this.props.count}


加一
减一
异步加一

);
}
}
Cannot set property 'state' of undefined

smox 2.0 重构


API 如图,目标:简化 API ,提高代码质量

  1. 移除 dispatch 等 api 的显式暴露
  2. 独创 path-proxy 机制,使用 path 来实现拆分 store,移除 model 机制
  3. 优化 proxy 递归,争取 Object.defineproperty 向下兼容
  4. 中间件机制要不要保留有待讨论

其他

  1. 使用 ts 进行代码书写
  2. 争取完善测试

争取寒假前重构完

effect with deps and instead of lifecycles?

In Vue, watch has source param, It will be a getter or a ref:

watch(ref, ()=>console.log(111))

It will return a cleanup:

const cleanup = watch()

This only happens while the component is initializing.

I want to add an API, similar to useeffect, to implement the life cycle at one time.

So……first, move soure to the end params:

watch(()=>console.log(111), [])

Second, return cleanup inside the callback:

watch(()=>{
  console.log('effect')
  retrun () => cleanup()
}, [])

This is consistent with useeffect and more ergonomic.

So shall we change the API name, such as

watch => effect

重新思考 smox 的 hooks 支持

关于<hooks 是否需要状态管理>,先看这篇我的回答:
https://www.zhihu.com/question/311822358/answer/598799280
差不多就是,不需要了……但是我们可以利用 hooks 来一次稍微大一点的手术

其实我一直在 react 内想做的是,将劫持(Proxy)引入 react,smox 是个入侵不重的引入方式(相对 mobx)而言
我在我的另一个框架 fre 的初始版本中,也企图使用劫持实现类似的 API,然后失败了

但是 smox 这边我突然觉得可以继续做下去

比如,以下的 API:

import { useData, useObserver } from 'smox'

function Counter() {
  const data = useData({ count: 0 })
  return useObserver(() => (
    <div>
      {data.count}
      <button onClick={() => data.count++}>+</button>
    </div>
  ))
}

和 vue-hooks 非常像,区别在于 vue-hooks 多了一个包裹函数,逼格瞬间没了
期望的结果是,我们的组件,除了 useState 这种状态管理的形式,还有 useData,后者是劫持的方式

使用 smox 这部分 API,给 react 的 hooks 生造一个劫持的功能

哦对,useObserver 接受一个函数,它负责将这个函数变成可观察的,和 mbox 的 autorun 作用一样

讨论:要不要这么搞?还有没有更好的 API 设计?

To do……

1. 移除 New Context API,使用 react hooks (useContext)
react 16 的 New Context API 有一定的局限性,比如无法在 componentDidMount 中引入 ,比如 <Context.Consumer> 等 hoc 会造成组件树的臃肿

2.使用 react 自带的一些 hooks ,比如 useReducer ……
我已经预感到,原先 1kb 的 smox ,这下可能缩减到……没几行代码了呜呜呜

这两天满课,预计周六开始搞::>_<::

顺便——
**会趁机发一个 react+smox 的 ssr 框架 **

结合 c 站 ssr 同构,我会给出一个性能超好的 ssr 解决方案。

记录

for (var i = 0; i < 26; i++) {
      for (var j = 0; j < 26; j++) {
        for (var k = 0; k < 26; k++) {
          let name =
            String.fromCharCode(65 + i) +
            String.fromCharCode(65 + j) +
            String.fromCharCode(65 + k)
          post('https://github.com/signup_check/username?suggest_usernames=true', {
            authenticity_token: 'u7gQqTDK7gVPXo0w6J2p / ak8lFcrM 0a0GRgy / YZ4Ev1LjV2hFNFGVpJdirwkytQxHNHW8 Qeu6ruJy3CX4WJg==',
            value: name
          }).then(res=>{
            console.log(res)
          })
        }
      }
    }

会引起很多不必要的更新

#所有用到store中的状态的组件都直接这样传一个store.state进去,如果只是修改了其中的某一个状态,会引起其他没用到这个状态的组件也更新,会引发很多意想不到的问题

JS.ORG CLEANUP

JS.ORG CLEANUP

Hello, it seems a js.org subdomain that was requested to target this repository no longer works.
The subdomain requested was smox.js.org and had the target of 132yse.github.io/smox.
It produced the following failures when tested as part of the cleanup:

  • HTTP: Failed with status code '404 Not Found'
  • HTTPS: Failed with status code '404 Not Found'

To keep the js.org subdomain you should add a page with reasonable content within a month so the subdomain passes the validation.
Failure to rectify the issues will result in the requested subdomain being removed from JS.ORGs DNS and the list of active subdomains.

If you are wanting to keep the js.org subdomain and have added reasonable content, YOU MUST reply to the main cleanup issue with the response format detailed at the top to keep the requested subdomain.

🤖 Beep boop. I am a robot and performed this action automatically as part of the js.org cleanup process. If you have an issue, please contact the js.org maintainers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.