Today, Hongmeng is finally released, and developers are finally “boiling”.

Source code hosting in the well-known open source platform code cloud, gitee.com/openharmony

I also downloaded the source code for the first time, studied for a night, and wrote a Hello World program, and also gave hongmeng document 2 PR.

Of course, I am most interested in the JS framework ace_lite_JsFWk, from the name can be seen that this is a very lightweight framework, the official introduction is “lightweight JS core development framework”.

When I looked at the source code it was really light. The core code is only 5 JS files, probably 300-400 lines of code. (No unit tests)

runtime-core\src\core\index.js

runtime-core\src\observer\observer.js

runtime-core\src\observer\subject.js

runtime-core\src\observer\utils.js

runtime-core\src\profiler\index.js

As the name suggests, this code implements an observer pattern. That is, it implements a very lightweight MVVM pattern. A responsive system is implemented using a similar attribute hijacking technique to VUe2. This should be one of the “three self-actualization” of the current training course. (Implement Promise, implement Vue, implement React)

Utils defines an Observer stack to hold the Observer. Subject defines the observed. When we look at an object, we see operations that hijack the properties of the object, and we see array functions like push, pop, and so on. This file should have the most code, 160 lines. Observer code is even simpler, 50 or 60 lines.

When developing, we compile and package the HML, CSS and JS files written by developers into JS bundles through Toolkit, and then parse the JS Bundle and run it into View components of C++ native UI for rendering.

“By supporting three-party developers to use declarative APIS for application development, data-driven view changes can avoid a lot of view operations, greatly reduce the difficulty of application development, and improve the development experience of developers”. It’s basically a small program development experience.

SRC core base framework_min_js.h, the compiled JS is compiled into runtime. Compiled JS files are less than 3K, which is really light enough.

The JS Runtime does not use V8, nor does it use jScore. Instead, I chose JerryScript. JerryScript is an ultra-lightweight JavaScript engine for the Internet of Things. It can execute ECMAScript 5.1 source code on devices with less than 64 KB of memory. This is why it is stated in the documentation that the HONGmeng JS framework supports ECMAScript 5.1.

The js framework as a whole uses about 96% of C/C++ code and 1.8% of JS code. Components written in the HTM file are compiled as native components. App_style_manager.cpp and the other seven or eight files are used to parse the CSS and ultimately produce the native layout.

Although there are several WEEx packages in the SDK, there are echoes of React. But there is nothing about yoga in C/C++ code (global search did not find). The packages in the SDK are just for loaders, presumably for parsing HTM components when webPack is packaged. Compile the HTM template into JS code.

On the whole, it went better than I expected.