-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6bdf327
Showing
13 changed files
with
2,468 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
.DS_Store | ||
*.log | ||
*.compiled.js | ||
/publishable |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.prettierrc | ||
.tslint.json | ||
.gitignore |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"printWidth": 180, | ||
"trailingComma": "all", | ||
"singleQuote": true | ||
} |
Empty file.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
(c) Copyright 2018 Filestack, all rights reserved. |
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<p align="center"> | ||
<a href="https://www.filestack.com"><img src="https://static.filestackapi.com/filestack-js.svg?refresh" align="center" width="250" /></a> | ||
</p> | ||
<p align="center"> | ||
<strong>Dependency free js async script loader maintained by @Filestack</strong> | ||
</p> | ||
|
||
## Installation | ||
|
||
``` | ||
npm install @filestack/loader | ||
``` | ||
|
||
## Usage | ||
|
||
### Loading JavaScript Modules | ||
|
||
If you have two modules `a.js` and `b.js` and you want to load `b` into `a`... | ||
|
||
```js | ||
// file a.js | ||
import { loadModule } from '@filestack/loader'; | ||
|
||
loadModule('module-id', 'url/to/b.js').then((b) => { | ||
b.helloWorld(); | ||
}); | ||
``` | ||
|
||
```js | ||
// file b.js | ||
import { registerModule } from '@filestack/loader'; | ||
|
||
const api = { | ||
helloWorld() { | ||
console.log('Hello world!'); | ||
}, | ||
}; | ||
|
||
// Module need to "tell" the loader that it's loaded and ready. | ||
registerModule('module-id', api); | ||
``` | ||
|
||
### Loading CSS | ||
|
||
```js | ||
import { loadCss } from '@filestack/loader'; | ||
|
||
loadCss('url/to/style.css').then(() => { | ||
console.log('Style loaded!'); | ||
}); | ||
``` | ||
|
||
# Development | ||
|
||
## Setup | ||
|
||
``` | ||
npm install | ||
``` | ||
|
||
## Testing | ||
|
||
### Unit | ||
|
||
``` | ||
npm test | ||
``` | ||
This command opens in the browser semi-manual tests. Those tests don't have watch, so you need to refire the command with each change. |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
export declare type ModuleDef = { | ||
promise?: Promise<any>; | ||
resolvePromise?: any; | ||
instance?: any; | ||
metadata?: any; | ||
}; | ||
export declare type Namespace = { | ||
modules: { | ||
[key: string]: ModuleDef; | ||
}; | ||
}; | ||
/** | ||
* Load multiple modules | ||
* | ||
* @param {*} modules | ||
*/ | ||
export declare const loadModules: (modules: any) => Promise<[unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown]>; | ||
/** | ||
* Load single module from url with given id | ||
* | ||
* @param {*} id - module id | ||
* @param {*} url | ||
*/ | ||
export declare const loadModule: (id: string, url: string) => Promise<any>; | ||
/** | ||
* Register that module is ready | ||
* | ||
* @param {string} id | ||
* @param {any} instance | ||
* @param {any} metadata - additional module metadata like version | ||
*/ | ||
export declare const registerModule: (id: string, instance: any, metadata: any) => void; | ||
/** | ||
* Load external css from given url | ||
* | ||
* @param {*} url | ||
*/ | ||
export declare const loadCss: (url: any) => Promise<unknown>; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.