├── .gitignore ├── tea.yaml ├── test └── index.test.js ├── src └── lazyLoadingComponents.js ├── LICENSE ├── package.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Directories 2 | node_modules/ 3 | dist/ 4 | coverage/ 5 | .cache/ 6 | 7 | # Files 8 | .env 9 | .DS_Store -------------------------------------------------------------------------------- /tea.yaml: -------------------------------------------------------------------------------- 1 | # https://tea.xyz/what-is-this-file 2 | --- 3 | version: 1.0.0 4 | codeOwners: 5 | - '0x9BAac40A197bbb110ae5B2f31342D8d15D734832' 6 | - '0xC4C902Ada8DB1dDae5e7641E4c392C1abF0b785A' 7 | quorum: 2 8 | -------------------------------------------------------------------------------- /test/index.test.js: -------------------------------------------------------------------------------- 1 | const assert = require('assert'); 2 | const lazyLoadComponent = require('../src/lazyLoadingComponents'); 3 | 4 | describe('Lazy Loading Components Test', function() { 5 | it('Should load component lazily', function() { 6 | return lazyLoadComponent('path/to/component.js') 7 | .then(() => { 8 | // Add your assertions here, e.g., check if component is loaded successfully 9 | assert.ok(true, 'Component loaded successfully'); 10 | }) 11 | .catch((error) => { 12 | // Handle error if component failed to load 13 | assert.fail(error); 14 | }); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /src/lazyLoadingComponents.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Function to lazy load components dynamically. 3 | * @param {string} componentPath - Path to the component file. 4 | * @returns {Promise} - Promise that resolves when component is loaded. 5 | */ 6 | function lazyLoadComponent(componentPath) { 7 | return new Promise((resolve, reject) => { 8 | const script = document.createElement('script'); 9 | script.src = componentPath; 10 | script.onload = () => { 11 | resolve(); 12 | }; 13 | script.onerror = (error) => { 14 | reject(error); 15 | }; 16 | document.body.appendChild(script); 17 | }); 18 | } 19 | 20 | module.exports = lazyLoadComponent; 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 ONE DIONYS 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "onedionys-lazy-loading-components", 3 | "version": "5.0.0", 4 | "description": "One Dionys (Lazy Loading Components) - Functions to incrementally load application components when needed.", 5 | "main": "src/lazyLoadingComponents.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/onedionys/onedionys-lazy-loading-components.git" 15 | }, 16 | "keywords": [ 17 | "onedionys", 18 | "tea", 19 | "package-manager", 20 | "lazy-loading-components" 21 | ], 22 | "author": "One Dionys", 23 | "license": "ISC", 24 | "bugs": { 25 | "url": "https://github.com/onedionys/onedionys-lazy-loading-components/issues" 26 | }, 27 | "homepage": "https://github.com/onedionys/onedionys-lazy-loading-components#readme", 28 | "dependencies": { 29 | "@types/chai": "^4.3.12", 30 | "@types/mocha": "^10.0.6", 31 | "chai": "^5.1.0", 32 | "mocha": "^10.3.0" 33 | }, 34 | "devDependencies": { 35 | "chai": "^5.1.0", 36 | "mocha": "^10.3.0" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Welcome to One Dionys - Lazy Loading Components! 👋

2 | 3 |

Functions to incrementally load application components when needed. 💖

4 | 5 |

6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

14 | 15 | ## 💾 Requirements 16 | 17 | * `Web Browser` - Can be used as an emulator to build applications. Example [Chrome, Firefox, Safari & Opera]. 18 | * `Internet` - Because many use CDN and to make it easier to find solutions to all problems. 19 | 20 | ## 🎯 How To Use 21 | 22 | #### Example Syntax 23 | 24 | ```javascript 25 | const lazyLoadComponent = require('lazy-loading-components'); 26 | 27 | lazyLoadComponent('path/to/component.js') 28 | .then(() => { 29 | // Component loaded successfully, you can now use it 30 | }) 31 | .catch((error) => { 32 | // Handle error if component failed to load 33 | }); 34 | ``` 35 | 36 | #### Explanation 37 | 38 | * This package provides a function `lazyLoadComponent` that allows you to dynamically load components in your web application. The function accepts the path to the component file as a parameter and returns a promise that resolves when the component is successfully loaded. 39 | 40 | #### Return Value 41 | 42 | * The `lazyLoadComponent` function returns a promise. If the component is loaded successfully, the promise resolves. If there is an error while loading the component, the promise rejects with an error object. 43 | 44 | ## 📆 Release Date 45 | 46 | * v1.0.0 : 08 March 2024 47 | * v1.0.1 : 11 March 2024 48 | * v4.0.0 : 11 March 2024 49 | * v4.0.1 : 14 March 2024 50 | * v4.0.2 : 18 March 2024 51 | * v5.0.0 : 31 March 2024 52 | 53 | ## 🧑 Author 54 | 55 | * Facebook : Oned Ionys 56 | * Instagram : @onedionys 57 | * Twitter : @onedionys 58 | * LinkedIn : @onedionys 59 | 60 | ## 📝 License 61 | 62 | * Copyright © 2024 One Dionys 63 | * **One Dionys - Lazy Loading Components is an open source project licensed under the MIT license** 64 | 65 | ## ☕️ Suppport & Donation 66 | 67 | Love One Dionys - Lazy Loading Components? Support this project by donating or sharing with others in need. 68 | 69 | 70 | 71 | **Made with ❤️ One Dionys** 72 | --------------------------------------------------------------------------------