Block management JavaScript framework for building complex pages in a simple way

Block management JavaScript framework for building complex pages in a simple way

2022-09-30 0 1,045
Resource Number 44044 Last Updated 2025-02-24
¥ 0HKD Upgrade VIP
Download Now Matters needing attention
Can't download? Please contact customer service to submit a link error!
Value-added Service: Installation Guide Environment Configuration Secondary Development Template Modification Source Code Installation

This issue recommends the front-end page block management framework — Magix.

Block management JavaScript framework for building complex pages in a simple way插图

As the front-end world continues to evolve, modern websites are becoming larger and more complex. In this case, Magix uses the idea of separating the site into pages and pages into blocks, and uses each independent block to build the page in the way of block connection, so that no matter how complex the page can be like piecing together a puzzle, realizing the simplification of complexity.

class=”pgc-h-arrow-right” data-track=”7″>

  • Easy to use : use the most original syntax, as long as you know html, css, javascript can be used out of the box
  • High efficiency : Blocks are independent of each other, which means that defined blocks can be reused anywhere to get more done with less effort
  • Future-oriented : For complex and large projects, Magix’s natural micro-front-end architecture, after simple configuration, allows independent projects to access smoothly as blocks

class=”pgc-h-arrow-right”>

  • Magix is suitable for single-page application (SPA) projects, and the original design goal is to make single-page application
  • Magix can also be used for traditional presentation pages. The more complex the page, the more worthwhile it is to use Magix
  • you can also apply Magix to only one section of the page, not the whole page
  • Magix does not support multiple instances, that is, only one Magix can exist on the same page. Even so, Magix can be mixed with other frameworks. You can even use Magix functions for certain sections of the page. Magix has high degrees of freedom and scalability

Block management JavaScript framework for building complex pages in a simple way插图1

class=”pgc-h-arrow-right”> install

magix currently relies on the scaffolding tool thx-cli, so the development, environment running, package compilation and other functions of magix project need to be based on thx-cli.

First we need to install thx-cli globally

// npm
npm install -g thx-cli

// yarn
yarn global add thx-cli

thx-cli will register thx as the global command after installation, we can directly use thx< command> [options] to use

So we can use the thx-v command to verify that the installation was successful. If the version number is shown, the installation is successful

Initialize

After installing thx-cli, we can start initializing the application.

We can use the thx init command to initialize the application. If we are initializing the application for the first time, thx-cli will prompt to install the Magix-related suite (thx-kit-magix) as follows:

After installing the package, select the template we initialized

Block management JavaScript framework for building complex pages in a simple way插图2

Finally enter the application name

Block management JavaScript framework for building complex pages in a simple way插图3

class=”pgc-h-arrow-right”> Application run and package build

Local run development

thx-cli provides the dev command for local application development. After successful application launch, the browser will be automatically opened

Block management JavaScript framework for building complex pages in a simple way插图4

Package build

thx-cli also provides the build command to package and build the application. The output of the built file is in the build directory

Block management JavaScript framework for building complex pages in a simple way插图5

Block management JavaScript framework for building complex pages in a simple way插图6

class=”pgc-h-arrow-right”>View base

View composition

Like native front-end development, a view typically consists of three files:

  • html file: template file, render page with data
  • css file: style file, style related to the current page
  • javascript file: essential file, responsible for all logic execution

With compiler support, css files can be replaced by less files, and typescript is also supported. In addition, html files and css files are not required for different block functions. For example, when the current view only provides functional expansion, only one js file

is allowed for template and style needs.

So what are the three files connected by? The answer is: @: placeholder

Let’s look ata concrete example:

When a view related file is structured as:

- index.ts
- index.html
- index.less

The code in the index.ts file is as follows:

import Magix from 'magix'

// 
magix.applyStyle('@:./index.less')

export default Magix.View.extend({
  tmpl:'@:./index.html' // 关联html文件
  assign(extra) {
  	this.set(extra)
	},
  async render() {
    await this.digest()
  }
})

You can see that the @: placeholder is important, but it’s not just about linking files, it’s also about introducing css variables.


View data rendering

We mentioned earlier that the html file will combine the data from the js file to render the page. How does this work? The first thing we need to understand is that each view has a data object . You’ve already seen these two functions in the previous code: this.set() and this.digest(). These two functions operate on data objects.

where the set function is used to set data in the view. When the function is called, an object is passed in, and the object is mixed into the data object of the current view.

and the digest function renders the view as , converting the template to real dom. It also supports accepting an object as a parameter that represents the setting data and renders the view simultaneously.

this.set({username:123}).digest()
//
this.digest({username:123})

Once a template in an html file has fetched dynamic data, it is then rendered using simple template syntax: < div> {{= username}}< /div> . The final rendering result of this node is < div> 123< /div>


> Connection between views

We’ve seen the composition and rendering of a view. So how do different views relate to each other? How does magix achieve flexible use between blocks?

Now let’s take an example: we have two views, a and b, and we want to display b in a, that is, we want to introduce b in a, what do we do?

Suppose the directory structure is as follows:

- a.ts
- a.html
- a.less
- b.ts
- b.html
- b.less

Here we introduce a property called mx-view, which magix uses to connect different blocks. For example, to introduce b into a, you only need to write in a.ML: < div mx-view=”@:./b”> < /div>

or you can use the tags that come with magix: < mx-vframe src=”@./b” /> After being compiled by the compiler, it will also be compiled the same as the former. Similarly, components in the component library, after compilation, will also become < div mx-view=” “> < /div> Nodes of this form.

Example

parent-child component communication

Block management JavaScript framework for building complex pages in a simple way插图7

Dynamic mount view

Block management JavaScript framework for building complex pages in a simple way插图8

—END—

Open source protocol: MIT

资源下载此资源为免费资源立即下载
Telegram:@John_Software

Disclaimer: This article is published by a third party and represents the views of the author only and has nothing to do with this website. This site does not make any guarantee or commitment to the authenticity, completeness and timeliness of this article and all or part of its content, please readers for reference only, and please verify the relevant content. The publication or republication of articles by this website for the purpose of conveying more information does not mean that it endorses its views or confirms its description, nor does it mean that this website is responsible for its authenticity.

Ictcoder Free Source Code Block management JavaScript framework for building complex pages in a simple way https://ictcoder.com/block-management-javascript-framework-for-building-complex-pages-in-a-simple-way/

Share free open-source source code

Q&A
  • 1. Automatic: After making an online payment, click the (Download) link to download the source code; 2. Manual: Contact the seller or the official to check if the template is consistent. Then, place an order and make payment online. The seller ships the goods, and both parties inspect and confirm that there are no issues. ICTcoder will then settle the payment for the seller. Note: Please ensure to place your order and make payment through ICTcoder. If you do not place your order and make payment through ICTcoder, and the seller sends fake source code or encounters any issues, ICTcoder will not assist in resolving them, nor can we guarantee your funds!
View details
  • 1. Default transaction cycle for source code: The seller manually ships the goods within 1-3 days. The amount paid by the user will be held in escrow by ICTcoder until 7 days after the transaction is completed and both parties confirm that there are no issues. ICTcoder will then settle with the seller. In case of any disputes, ICTcoder will have staff to assist in handling until the dispute is resolved or a refund is made! If the buyer places an order and makes payment not through ICTcoder, any issues and disputes have nothing to do with ICTcoder, and ICTcoder will not be responsible for any liabilities!
View details
  • 1. ICTcoder will permanently archive the transaction process between both parties and snapshots of the traded goods to ensure the authenticity, validity, and security of the transaction! 2. ICTcoder cannot guarantee services such as "permanent package updates" and "permanent technical support" after the merchant's commitment. Buyers are advised to identify these services on their own. If necessary, they can contact ICTcoder for assistance; 3. When both website demonstration and image demonstration exist in the source code, and the text descriptions of the website and images are inconsistent, the text description of the image shall prevail as the basis for dispute resolution (excluding special statements or agreements); 4. If there is no statement such as "no legal basis for refund" or similar content, any indication on the product that "once sold, no refunds will be supported" or other similar declarations shall be deemed invalid; 5. Before the buyer places an order and makes payment, the transaction details agreed upon by both parties via WhatsApp or email can also serve as the basis for dispute resolution (in case of any inconsistency between the agreement and the description of the conflict, the agreement shall prevail); 6. Since chat records and email records can serve as the basis for dispute resolution, both parties should only communicate with each other through the contact information left on the system when contacting each other, in order to prevent the other party from denying their own commitments. 7. Although the probability of disputes is low, it is essential to retain important information such as chat records, text messages, and email records, in case a dispute arises, so that ICTcoder can intervene quickly.
View details
  • 1. As a third-party intermediary platform, ICTcoder solely protects transaction security and the rights and interests of both buyers and sellers based on the transaction contract (product description, agreed content before the transaction); 2. For online trading projects not on the ICTcoder platform, any consequences are unrelated to this platform; regardless of the reason why the seller requests an offline transaction, please contact the administrator to report.
View details

Related Source code

ICTcoder Customer Service

24-hour online professional services