Git Product home page Git Product logo

ui5-errorhandler-sample's Introduction

npmpackagesample

This sample shows how to use npm packages. Two examples are shown here:

  • How to consume a UI5 AMD style module
  • How to consume a classic js class

We will consume @marianfoo/ui5-errorhandler.
Repo is here https://github.com/marianfoo/ui5-errorhandler
The two options are in UI5 style ErrorHandler and js class style ErrorHandler.

UI5 AMD style module

NPM Package

In npm package ui5.yaml , the ressource path is defined as:

resources:
  configuration:
    paths:
      "/resources/cc/errorhandler/": "./"

Consume in UI5 Sample App

In the package.json file, we have the following entries:

    "dependencies": {
        "@marianfoo/ui5-errorhandler": "^0.0.4"
    },
    "ui5": {
        "dependencies": [
            "ui5-middleware-simpleproxy",
            "@marianfoo/ui5-errorhandler"
        ]
    }

Consume it in the UI5 app with the resource path as defined in the npm package (Component.js):

sap.ui.define(
    ["sap/ui/core/UIComponent", "sap/ui/Device", "de/marianzeis/npmpackagesample/model/models", 
    "cc/errorhandler/ErrorHandler"
    ],
    function (UIComponent, Device, models, ErrorHandler) {
        "use strict";

        return UIComponent.extend("de.marianzeis.npmpackagesample.Component", {
            metadata: {
                manifest: "json",
            },
            init: function () {
                // call the base component's init function
                UIComponent.prototype.init.apply(this, arguments);

                // enable routing
                this.getRouter().initialize();

                // set the device model
                this.setModel(models.createDeviceModel(), "device");

                this._oErrorHandler = new ErrorHandler(this);
            },
        });
    }
);

javaScript Class style module (any other npm package)

In the ui5.yaml file, we have the following entries:

server:
    customMiddleware:
        ...
        - name: ui5-tooling-modules-middleware
          afterMiddleware: compression
builder:
  customTasks:
  - name: ui5-tooling-modules-task
    afterTask: replaceVersion

In package.json:

    "devDependencies": {
        "ui5-tooling-modules": "^0.1.2",
        "@marianfoo/ui5-errorhandler": "^0.0.1"
    },
    "ui5": {
        "dependencies": [
            "ui5-tooling-modules"
        ]
    }

We consume it in Component.js with the npm package name:

sap.ui.define(
    ["sap/ui/core/UIComponent", "sap/ui/Device", "de/marianzeis/npmpackagesample/model/models", 
    "@marianfoo/ui5-cc-errorhandler/ErrorHandlerClass"],
    function (UIComponent, Device, models, ErrorHandler) {
        "use strict";

        return UIComponent.extend("de.marianzeis.npmpackagesample.Component", {
            metadata: {
                manifest: "json",
            },
            init: function () {
                // call the base component's init function
                UIComponent.prototype.init.apply(this, arguments);

                // enable routing
                this.getRouter().initialize();

                // set the device model
                this.setModel(models.createDeviceModel(), "device");

                this._oErrorHandler = new ErrorHandler(this);
            },
        });
    }
);

Now the javaScript class is wrapped:

Before

var BaseObject = require('sap/ui/base/Object');
var MessageBox = require('sap/m/MessageBox');

module.exports = class ErrorHandler extends BaseObject {
// ************************************************************************************************************
		// Constructor
		// ************************************************************************************************************

		/**
		 * Constructor Method of the error handler. Initialises the error handler for the default model of the component.
		 * @public
		 * @constructor
		 * @param {sap.ui.core.UIComponent} oComponent Reference to the component of the app
		 * @method module:controller/ErrorHandler#constructor
		 */
		 constructor(oComponent) {

After (how the ui5 app is consuming it)

sap.ui.define(['sap/ui/base/Object', 'sap/m/MessageBox'], (function (require$$0, require$$1) { 'use strict';

	function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

	var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
	var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);

	var BaseObject = require$$0__default["default"];
	var MessageBox = require$$1__default["default"];

	var ErrorHandlerClass = class ErrorHandler extends BaseObject {
	// ************************************************************************************************************
			// Constructor
			// ************************************************************************************************************

			/**
			 * Constructor Method of the error handler. Initialises the error handler for the default model of the component.
			 * @public
			 * @constructor
			 * @param {sap.ui.core.UIComponent} oComponent Reference to the component of the app
			 * @method module:controller/ErrorHandler#constructor
			 */
			 constructor(oComponent) {

Credits

This project has been generated with ๐Ÿ’™ and easy-ui5

ui5-errorhandler-sample's People

Contributors

marcelschork avatar marianfoo avatar

Watchers

 avatar  avatar

Forkers

marcelschork

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.