Giter Site home page Giter Site logo

greact's People

Contributors

melniknow avatar mrsky1001 avatar pain64 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

melniknow

greact's Issues

refactor: GReact: rename 'mount' to 'render', metadata system (17K)

PR1: rename 'mount' -> 'render'

  1. Component[0, 1, 2, 3].mount -> render
  2. jstack.greact.dom.GReact.mmount -> mount, mmountAwaitView -> renderAwaitView
  3. переименовать в omsu_tutor_payload и uikit

PR2: refactor metaprogramming system

регистрация AST процессора:
/src/main/resources/META-INF/service/jstack.greact.AstProcessor

jstack.greact.AstProcessor {
    void init(Context context);
    void apply(JCCompilationUnit cu);
}

load processors: https://www.baeldung.com/java-spi

Переносим функциональность:
  1. CodeView
  2. MemberRef переносим функционал
  3. Reflexive удаляется полностью

new Grid API

   @DoNotTranspile public Grid(@Reflexive T[] data) {
        this.data = data;
   }
   public Grid(T[] data, Column<T, ?>[] columns) {
       this.data = data;
       this.columns = columns;
   }

Usage:

        // basic constructor
        new Grid<>(data) {{
        }};

        // delegates to
        new Grid<>(data, Array.of(
            new Column<>("the x", XY::x),
            new Column<>("the y", XY::y)
        )) {{
            this.title = "x and y";
        }};

        // MemberRef delegates to
        new Grid<>(data, Array.of(
            new Column<>("the x", JSExpression.of("...")),
            new Column<>("the y", JSExpression.of("..."))
        )) {{
            this.title = "x and y";
        }};

Используем TreeTranslator для подмены MemberRef на JSExpression

new TreeTranslator() {
            @Override public void visitReference(JCTree.JCMemberReference tree) {
                if (isMemberRefSymbol(ref.type.tsym)) {
                    this.result = ...
                } else
                    this.result = tree;
            }
        };

NB: использование TreeMaker можно посмотреть в RPCPlugin и NewClassPatcher
NB: алгоритм именования колонок: Column.java:[44-75] полностью переносится в compile-time (GridProcessor)

JSExpression.of: varargs of used variables (12K)

JSExpression.of(String jsCode, Object... args)

usage:

// Supported patterns
// 1. identifiers
JSExpression.of(":1 + :2", a, b) // a + b
JSExpression.of(":1", this) // this
// 2. select expression (recursive) with identifier at tail
JSExpression.of(":1 + 1", a.b) // a.b + 1
JSExpression.of(":1 + 1", a.b.c) // a.b.c + 1
JSExpression.of(":1 + 1", this.a) // this.a + 1
// 3. method reference for this and other class static method
JSExpression.of(":1()", this::aMethod) // this._aMethod()
JSExpression.of(":1()", ThisClass::aStaticMethod) // this.constructor._aStaticMethod()
JSExpression.of(":1()", Class::aStaticMethod) // pkg_Class.constructor._aStaticMethod()
// 4. support cast
JSExpression.of(":1 + 1", (Object) this.a) // this.a + 1

escaping:

JSExpression.of("\\:1", a) // :1

NB: strict check for allowed patterns needed
NB: reuse compiler infrastructure for expression generation

RPC: simplify configuration (15K)

RPC server creation
// goal:
public static class Server extends RPC<Context> { }
// converts to:
public static class Server extends RPC<Context> { }
    Server() { super("omsu.tpayload.Main.Server", "omsu.tpayload.js"); }
}

resource management (css, js, etc)

    class Bundle {
        private final Map<String, Supplier<String>> resources = new HashMap<>();

        void handleResource(
            String resourceName,
            Consumer<Integer> setStatusCode,
            Consumer<String> setContentType,
            OutputStream output
        ) {
            var found = resources.get(resourceName);
            if (found != null) {
                if (resourceName.endsWith(".css"))
                    setContentType.accept("text/css");
                if (resourceName.endsWith(".js"))
                    setContentType.accept("text/javascript");

                setStatusCode.accept(200);
                setData.accept(found.get());
            } else {
                setStatusCode.accept(404);
                setData.accept("not found");
            }
        }
    }

// usage:
var bundle = Loader.bundle("""
            <title>Нагрузка преподавателя</title>
            <link rel="icon" href="images/favicon.ico" type="image/x-icon">
            """, ApplicationsService.class
 );
Spark.get("/*", (req, res) -> {
            bundle.handleResource(
                req.pathInfo(), res::status,
                res::type, res.raw().getOutputStream()
            );
            return null;
 });

RPC invocation

server.handle(
    new Context(db, reportRunner, req.session()),
    res::status,  res::type, req.raw().getInputStream()
);

Project fails to build

Following error generated in Jenkins:

22:17:55 > Task :compileTestJava FAILED
22:17:55 /var/lib/jenkins/workspace/iias-greact/plugin/src/test/java/util/TestServer.java:8: error: appBasePackage has private access in RPC
22:17:55 public TestServer() {super(appBasePackage);}
22:17:55 ^
22:17:55 Note: Some input files use preview language features.
22:17:55 Note: Recompile with -Xlint:preview for details.
22:17:55 1 error
22:17:55
22:17:55 FAILURE: Build failed with an exception.
22:17:55
22:17:55 * What went wrong:
22:17:55 Execution failed for task ':compileTestJava'.
22:17:55 > Compilation failed; see the compiler error output for details.22:17:55 > Task :compileTestJava FAILED
22:17:55 /var/lib/jenkins/workspace/iias-greact/plugin/src/test/java/util/TestServer.java:8: error: appBasePackage has private access in RPC
22:17:55 public TestServer() {super(appBasePackage);}
22:17:55 ^
22:17:55 Note: Some input files use preview language features.
22:17:55 Note: Recompile with -Xlint:preview for details.
22:17:55 1 error
22:17:55
22:17:55 FAILURE: Build failed with an exception.
22:17:55
22:17:55 * What went wrong:
22:17:55 Execution failed for task ':compileTestJava'.
22:17:55 > Compilation failed; see the compiler error output for details.22:17:55 > Task :compileTestJava FAILED
22:17:55 /var/lib/jenkins/workspace/iias-greact/plugin/src/test/java/util/TestServer.java:8: error: appBasePackage has private access in RPC
22:17:55 public TestServer() {super(appBasePackage);}
22:17:55 ^
22:17:55 Note: Some input files use preview language features.
22:17:55 Note: Recompile with -Xlint:preview for details.
22:17:55 1 error
22:17:55
22:17:55 FAILURE: Build failed with an exception.
22:17:55
22:17:55 * What went wrong:
22:17:55 Execution failed for task ':compileTestJava'.
22:17:55 > Compilation failed; see the compiler error output for details.

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.