Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
pcholuj committed Mar 18, 2020
0 parents commit 6bdf327
Show file tree
Hide file tree
Showing 13 changed files with 2,468 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.DS_Store
*.log
*.compiled.js
/publishable
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.prettierrc
.tslint.json
.gitignore
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 180,
"trailingComma": "all",
"singleQuote": true
}
Empty file added CHANGELOG.md
Empty file.
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(c) Copyright 2018 Filestack, all rights reserved.
68 changes: 68 additions & 0 deletions README.md
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.
38 changes: 38 additions & 0 deletions dist/index.d.ts
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>;
120 changes: 120 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6bdf327

Please sign in to comment.