📜  gi js - Javascript (1)

📅  最后修改于: 2023-12-03 15:30:54.515000             🧑  作者: Mango

Gi JS - JavaScript

Gi JS Logo

Gi JS is a modern, lightweight micro-framework for JavaScript, designed to help developers easily create scalable and maintainable applications.

Features
  • Modular architecture: Gi JS uses a modular architecture that makes it easy to create applications in a modular way. Each module is responsible for a specific aspect of the application and can be independently developed and tested.

  • Event-driven programming: Gi JS supports event-driven programming, allowing developers to create applications that respond to user actions and system events.

  • Dependency injection: Gi JS has a built-in dependency injection mechanism that makes it easy to manage dependencies between modules and reduce coupling between components.

  • Asynchronous programming: Gi JS provides a simple and efficient way to write asynchronous code using promises and async/await.

  • Browser and Node.js support: Gi JS can be used both in the browser and in Node.js, making it a versatile framework for building web applications.

Getting Started

To get started with Gi JS, you first need to install it using npm:

npm install gi-js

Once you have installed Gi JS, you can create a new application using the Gi JS CLI:

gi-js create my-app

This will create a new Gi JS application called my-app.

Creating Modules

Gi JS applications are built using modules. Each module is a self-contained unit of functionality that can be independently developed and tested.

To create a new module, use the gi-js generate command:

gi-js generate module my-module

This will create a new module called my-module in the src/app/my-module directory.

Handling Events

Gi JS uses an event-driven approach to handle user actions and system events. To handle an event, you first need to define an event listener:

const myButton = document.getElementById('my-button');
myButton.addEventListener('click', () => {
  console.log('Button clicked!');
});
Dependency Injection

Gi JS uses a built-in dependency injection mechanism to manage dependencies between modules and reduce coupling between components.

To inject a dependency into a module, use the @Inject decorator:

import { Injectable, Inject } from 'gi-js';

@Injectable()
class MyService {
  constructor(@Inject('my-dependency') myDependency) {
    this.myDependency = myDependency;
  }
}
Asynchronous Programming

Gi JS provides a simple and efficient way to write asynchronous code using promises and async/await.

To use async/await in Gi JS, use the async keyword to define an asynchronous function:

async function fetchUser(id) {
  const response = await fetch(`/api/users/${id}`);
  const user = await response.json();
  return user;
}
Conclusion

Gi JS is a powerful and flexible framework for building web applications in JavaScript. Its modular architecture, event-driven programming model, and built-in dependency injection make it easy to create scalable and maintainable applications. Give it a try and see what you can create!


Author: @gijs-dev

License: MIT