-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added debounce to change file detector
- Loading branch information
Showing
4 changed files
with
87 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,71 @@ | ||
## Modules | ||
|
||
Thes files inside this folder are going to be injected to the global state and components using them will get only their references, so, saving | ||
size for the final bundle file. | ||
The files inside this folder are going to be injected only once and their references will be used throughout the app, thus reducing the final size of the final file. To add a file to be compiled as module, just add it to the `src/modules` folder. | ||
|
||
WARNING: If you want to use `props` inside the modules, you must pass it as a parameter. Modules live at the very top layer of Além and can't automatically access the props where it's being used. | ||
|
||
## When should I put files here? | ||
|
||
You should place files here when they are repeatedly imported into the project. Remembering again that they will not have access to the properties where they are being used automatically. Therefore, you must pass the necessary properties per parameter. | ||
|
||
Example: | ||
|
||
**Module files** | ||
|
||
```ts | ||
// src/modules/routesProps.ts Module | ||
export const routes = { | ||
HOME: "home"; | ||
PROFILE: "profile"; | ||
EDIT_PROFILE: "profile/edit" | ||
} | ||
|
||
// "parentProps" - props passed by the caller | ||
export const logParams = (parentProps: any) => { | ||
console.log(parentProps); | ||
} | ||
``` | ||
|
||
```ts | ||
// src/modules/Banner.tsx Module | ||
import { routes } from "./modules/parentProps"; | ||
|
||
const bannerText = "This is my banner!"; | ||
|
||
type BannerProps = { label: string }; | ||
|
||
const Banner = ({ label }: BannerProps) => { | ||
const availableRoutes = Object.keys(routes).join(", "); | ||
|
||
return ( | ||
<> | ||
<h3>{bannerText}</h3> | ||
<p>{label}</p> | ||
<p>Available routes: {availableRoutes}</p> | ||
</> | ||
); | ||
}; | ||
export default Banner; | ||
``` | ||
|
||
**Using module** | ||
|
||
```tsx | ||
// src/MyStatefulComponent.tsx | ||
import { useEffect, props } from "alem"; | ||
import { logParams } from "./modules/parentProps"; | ||
import Banner from "./modules/Banner"; | ||
|
||
const MyStatefulComponent = () => { | ||
//... | ||
useEffect(() => { | ||
logParams(props); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<Banner label="just a simple banner" /> | ||
</> | ||
); | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters