Giter Club home page Giter Club logo

loader's Introduction

Proposal for React Markup Language(RML)

中文文档

RML is a simple, easy-to-use, full-featured template markup language that can help developers better separate logic and view. RML is a continuation of JSX & JSX+ in syntax style, but its routines are not variables. You cannot determine whether to generate an instance by dynamically executing logic, but you can use x-if and x-for instead of corresponding capabilities.

Problem to solve

  1. Difficulty in implementation with some pre-compiled scenarios. Sometimes it is necessary to compile a multi-tree describing the DOM structure in advance. If this problem can be solved, the applet, Eagel, SSR, and Solution solutions will be simpler and more efficient
  2. Visualize the output, you need to be able to edit it twice
  3. JSX has poor development experience on some common features (such as loops, conditions). The template syntax can make up for this.

Template Function

  • Scope
    • The accessible variables in the template come from the scope, which is an externally assigned object
  • Child node slot
  • Condition x-if
    • You can fill in any value in condition judgment, same as JSX +
  • Loop with directive: x-for
    • Same as JSX +
  • Value interpolation {foo}
    • Performs the same as JSX, but does not allow template insertion
    • Allow JS literals, variables, expressions
  • Component import (import)
    • The import syntax is a reference statement that will be replaced with an import statement when compiled into JS. The path pointed to by src is the JS path by default

Template Stynax

  • Follow XML template syntax
  • import tag, used to import template dependencies or other parts
  • from specifies the path relationship with the current template
  • class / className is ok
  • Support JSX+
  • {} syntax is the way to bind value, which can bind any data in scope

Example

// ----- component.rml -----
<script>
 import {useState, useCallback} from 'rax';
  
 export default function (props) {
  const [foo, setFoo] = useState (true);
  const handleClick = useCallback ((evt) => {
    // todo with evt.
  }, [foo]);

  return {
    color: 'yellow',
    handleClick,
    foo,
  };
}
</script>

<style>
  @import './index.css';
  .foo {
    color: red;
  }
</style>

<import default="View" from="rax-view" /> // import View from 'rax-view';

<View>
  {"Interpolation"} // Literal literal
  {foo} // Identifier variable
  {foo + '...'} // Expression binary expression
  {foo? '1': '2'} // Expression ternary expression
  {fn (...)} // Expression
  {...} // other expressions
  <View x-slot:header className="foo" onTouchMove={handleClick}> property binding, event handler binding </View>
  <View x-for="item in list"> loop node {item} </View>
  <View x-if={isLoading}> Condition node if </View>
  <View x-elseif={condition}> condition node elseif </View>
  <View x-else> condition node else </View>
  <slot name="header"> Child nodes </slot>
</View>

loader's People

Contributors

alvinhui avatar wssgcg1213 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

danielxuuuuu

loader's Issues

Template Syntax for annotations

By design RML Template Syntax is follow XML Template Syntax, Annotations in XML should be:

<div>Hi</div>
<!-- <span>Alvin</span> -->

But now the syntax of the Loader implementation is JSX:

<div>Hi</div>
{/* <span>Alvin</span> */}

CSS Modules Problem

Code:

<style lang="scss" module>
  .container {
    .strong {
      font-weight: bold;
    }
  }
</style>
<div className="container">
  <span className="strong">Class 样式</span>
</div>

Render result:

image

No strong style appears to be generated.

Variable scope of template

By design, the variable scope of the template should come from the return value of the function:

<script>
export default function(props) {
  return {
    value: '123'
  };
}
</script>

<div>
  {value}
</div>

The actual implementation is:

<script>
export default function() {
  return {
    text: 123
  };
}
</script>

<div>
  <span>变量:</span>
  <span>{text}</span> {/* 123 */}
  <span>{props.text}</span> {/* 123 */}
</div>

I never defined props and props is not returned in return value.

If I use props as the return value:

<script>
export default function(props) {
  return {
    props
  };
}
</script>

 <div>
  <span>变量:</span>
  <span>{props.text}</span> {/* undefined */}
  <span>{props.props.text}</span> {/* text value */}
</div>

This implementation is inconsistent with the design.

Support inline expression

Object:

<script>
  export default function () {
   return {
     color: 'yellow',
   };
 }
 </script>
<span style={{color: color}}>
  object
</span>

Function:

<Button type="primary" onClick={function() {
  alert(1);
}}>
  click
</Button>

Support import RML file without suffix

Now I have to add the suffix manually when import the RML file:

  1. In generic files: import Home from '@/pages/Home/index.rml';
  2. In RML files: <import default="Guide" from="@/components/Guide.rml" />

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.