Skip to content

Commit 9c5b62b

Browse files
lilingxi01gitbook-bot
authored andcommitted
GitBook: [#5] No subject
1 parent da75104 commit 9c5b62b

13 files changed

+245
-2
lines changed
402 KB
Loading
402 KB
Loading

README.md

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,72 @@
1-
# launchpad-js-docs
2-
Launchpad Docs - The documentation repo for Launchpad (JS) library.
1+
---
2+
description: A modern API hook management system.
3+
layout: landing
4+
---
5+
6+
# Meet the Launchpad
7+
8+
9+
10+
![](<.gitbook/assets/Launchpad JS Cover (1).png>)
11+
12+
{% hint style="info" %}
13+
**WIP:** This documentation is still a Work In Progress. We are happy to hear from you about any suggestion or any issue that we have!
14+
{% endhint %}
15+
16+
Launchpad helps you quickly and painlessly integrate the front-end user interface with API calls (or mock calls) throughout the entire life cycle of your application.
17+
18+
It is a brand new idea on modularizing the fetching session (the API call from server to client, or a pure local call that happens behind the UI codes) and being ease with any change that may happen on an API algorithm (or even the mock one).
19+
20+
With Launchpad, you can define an API hook by writing its schema – including how every state turns, how API request will be fired, and everything you can imagine.
21+
22+
The coolest thing is that UI developer can call API by simply calling the hook function, with loading state built-in and their favorite objects as parameters.
23+
24+
## Understanding the Architecture
25+
26+
Launchpad is an additional layer lying between the front-end application and API calls. A Launchpad session can take input, convert arguments into proper JSON, and then send package to the back-end. When back-end replies, Launchpad will update the exposed state variable based on how it was configured.
27+
28+
So in the low-level, Launchpad is simply wrapping the essential algorithm by using hooks, and exposing most-needed APIs for a session. It saves a lot of time for UI developers to write fetching algorithm and manage annoying states (e.g. loading, error, and more) in UI files.
29+
30+
## Getting Started
31+
32+
### Guides: Make your first step
33+
34+
Follow our handy guides to get started on the basics as quickly as possible:
35+
36+
{% content-ref url="guides/installation.md" %}
37+
[installation.md](guides/installation.md)
38+
{% endcontent-ref %}
39+
40+
{% content-ref url="guides/your-first-session.md" %}
41+
[your-first-session.md](guides/your-first-session.md)
42+
{% endcontent-ref %}
43+
44+
{% hint style="info" %}
45+
**Why guides:** Follow our guide will be the best way to understand why you may need to use Launchpad. Please understand that not everyone needs it, so just use-it-when-you-need.
46+
{% endhint %}
47+
48+
### Fundamentals: Dive a little deeper
49+
50+
Learn the fundamentals of Launchpad to get a deeper understanding of our main features:
51+
52+
Want to build an API call that is not just a simple call? Follow our example to make sure that you are using it right!
53+
54+
{% content-ref url="fundamentals/design-a-complex-session.md" %}
55+
[design-a-complex-session.md](fundamentals/design-a-complex-session.md)
56+
{% endcontent-ref %}
57+
58+
Want to integrate Launchpad with authorization? We can handle the authorization stuff for you, built-in. Check our guide on authorization flow and you are good to go!
59+
60+
{% content-ref url="fundamentals/authorization-flow.md" %}
61+
[authorization-flow.md](fundamentals/authorization-flow.md)
62+
{% endcontent-ref %}
63+
64+
Want to make some changes globally? See if you can do that by setting up a configuration file!
65+
66+
{% content-ref url="fundamentals/configuration.md" %}
67+
[configuration.md](fundamentals/configuration.md)
68+
{% endcontent-ref %}
69+
70+
## Credits
71+
72+
Greatly thanks to Alex (Chaolong) for giving the idea on the name of some API properties.

SUMMARY.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Table of contents
2+
3+
* [Meet the Launchpad](README.md)
4+
5+
## Guides
6+
7+
* [Installation](guides/installation.md)
8+
* [Your First Session](guides/your-first-session.md)
9+
10+
## Fundamentals
11+
12+
* [Design a complex session](fundamentals/design-a-complex-session.md)
13+
* [Authorization flow](fundamentals/authorization-flow.md)
14+
* [Configuration](fundamentals/configuration.md)
15+
16+
## Migration
17+
18+
* [v0.0 -> v0.1](migration/v0.0-greater-than-v0.1.md)
19+
20+
## API
21+
22+
* [Session API](api/session-api.md)
23+
* [Ignition API](api/ignition-api.md)
24+
25+
## About
26+
27+
* [Changelog](about/changelog.md)

about/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Changelog
2+

api/ignition-api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ignition API
2+

api/session-api.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Session API
2+
3+
{% hint style="info" %}
4+
**Good to know:** depending on the product you're building, it can be useful to explicitly document use cases. Got a product that can be used by a bunch of people in different ways? Maybe consider splitting it out!
5+
{% endhint %}

fundamentals/authorization-flow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Authorization flow
2+
3+
{% hint style="info" %}
4+
**Good to know:** Splitting your product into fundamental concepts, objects, or areas can be a great way to let readers deep dive into the concepts that matter most to them.
5+
{% endhint %}

fundamentals/configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Configuration
2+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
description: >-
3+
Launchpad makes building a complex session easy. Follow this documentation and
4+
get a sense on how you can use most out of it!
5+
---
6+
7+
# Design a complex session
8+
9+
## What is a session?
10+
11+
### Session Reusability
12+
13+
For reusability, you can configure a session and ignite it as many as you like, and wherever you want.
14+
15+
The recommended way to configure the launchpad session is writing them in a separate file, thus developers can maintain the API caller without changing the code at UI section.

guides/installation.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Installation
2+
3+
The package is released on different platforms for different programming languages. Pick the one you are using, and follow the instruction to install the Launchpad!
4+
5+
## JavaScript / TypeScript
6+
7+
{% tabs %}
8+
{% tab title="React" %}
9+
The package for React is published on NPM. You can use following command to install it into your project.
10+
11+
```bash
12+
npm install @taci-tech/launchpad-js
13+
```
14+
{% endtab %}
15+
16+
{% tab title="Svelte" %}
17+
The Svelte version is not released yet. Please check back later.
18+
{% endtab %}
19+
{% endtabs %}
20+

guides/your-first-session.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
description: >-
3+
There are only two steps to use Launchpad: create a session, and then ignite
4+
it. In this example, I am going to show you how to create your first Launchpad
5+
session and how to ignite it!
6+
---
7+
8+
# Your First Session
9+
10+
## What is a Session?
11+
12+
You can understand that one session is one API caller in a context. A context could be a page, a modal, a function, a component, and not necessary their children.
13+
14+
## Understand the Session
15+
16+
There are four lifecycles in a Launchpad session:
17+
18+
* **On Start:** It executes when the session is first inserted into the code. Usually happens before a page is loading. In React, it is the start value of a state, when no any `useEffect` is executed.
19+
* **On Mount:** It executes when the session is mounted into the client. Usually happens when a page is loaded, a component is loaded, or an application is loaded. In React, it is the first `useEffect`.
20+
* **On Override:** Most of the APIs require information from front-end (e.g. UUID, filter settings, etc.). So, _Override_ is the behavior that the front-end are setting parameters of the session. Launchpad can then re-make the API call, update information, or do anything you need.
21+
* **On Unmount:** It executes when the session is going to be unmounted from the client. Usually happens when the lifecycle of a page is ended. You can unregister the listeners that were registered when page was mounted, or you can do anything you need. In React, it can be understand as the return function of an empty `useEffect` function.
22+
23+
## Smallest Example
24+
25+
{% tabs %}
26+
{% tab title="React" %}
27+
{% hint style="info" %}
28+
In this example, we are using JavaScript.
29+
{% endhint %}
30+
31+
### Example
32+
33+
A session object is fairly simple –– just a JavaScript object notation.
34+
35+
In this example, we are not going to send an API call because that is actually optional to the session! We will mention that in the _Fundamental_ section.
36+
37+
```javascript
38+
const test = () => {
39+
return {
40+
// The start value.
41+
onStart: () => null,
42+
// The callback function when the session is mounted.
43+
onMount: ({ setState }) => {
44+
setState(1);
45+
},
46+
// The callback function when the `setParam` is called.
47+
onOverride: ({ state, setState, newValue }) => {
48+
setState(state + newValue);
49+
},
50+
};
51+
};
52+
```
53+
54+
The reason we wrap it as a function and then return a JSON is that we can have local variables inside the scope of this function. So you can use some variables to store things between different stages. But please be careful on what you store because it may violate the rule of React hook.
55+
56+
You have done creating the session! Now, let us ignite it in React.
57+
58+
It is similar to other hooks –– we got your back with a hook function `useLPSession`.
59+
60+
```javascript
61+
const YourFunctionalComponent = () => {
62+
const { data, setParam } = useLPSession(test());
63+
return (...);
64+
}
65+
```
66+
67+
That is it! After that, you have a state variable `data` that has the information you need, and an override function `setParam` to send information to the session. Every time you call `setParam` will update the `data` automatically based on your session settings.
68+
{% endtab %}
69+
70+
{% tab title="Svelte" %}
71+
Svelte version is still under development. Check back later!
72+
{% endtab %}
73+
{% endtabs %}
74+
75+
## Why Launchpad Session?
76+
77+
You may feel that the Launchpad is over-powered in this case. The same functionality can also be achieved by using `useState`. But here are some use cases that you may want to use Launchpad over vanilla hooks:
78+
79+
* When you have an algorithm that may need to be changed over time. You can choose to write a function and then call the function before every state set. In a collaborative scenario, it is not perfect. By using Launchpad, the only things you exposed to other folks (who use your session) are the returned data, a simple set function, and a built-in loading indicator. It is safer, cleaner, and easier.
80+
* When things become complicated (e.g. You are going to make a fetch request with the given data and set the result onto the state). If you choose vanilla hooks, you will write a bunch of things, which make your code not intuitive and decrease the reusability between different API calls.
81+
82+
{% hint style="warning" %}
83+
**Maintainability:** In general, we recommend to write the session in a file that separates from the front-end UI components for a better maintainability. However, it is just an object notation, so you can write it wherever you like!
84+
{% endhint %}
85+

migration/v0.0-greater-than-v0.1.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# v0.0 -> v0.1
2+
3+
In this update, we made a significant change on a property name.
4+
5+
{% tabs %}
6+
{% tab title="React" %}
7+
* **One of the exposed igniter properties has a new name!** We changed `setData` to `setParam` to avoid further confusion on passing parameters into the launchpad. **Be sure to replace all** `setData` to `setParam`.
8+
{% endtab %}
9+
{% endtabs %}
10+

0 commit comments

Comments
 (0)