npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ui5-typed-model

v1.1.0

Published

A strictly typed wrapper of a UI5 JSON model

Downloads

6

Readme

UI5 TypedModel

API Reference

A strictly typed wrapper of a UI5 JSON model.

Installation

Use npm to install:

npm install ui5-typed-model

Please note that this library works with TypeScript v5.0 or higher and depends on the official ESM-style UI5 types @openui5/types or @sapui5/types which will not be automatically installed.

Furthermore, a code transformation is needed to transform UI5-style ESM imports into valid UI5 code, e.g. with Babel and either babel-plugin-ui5-esm or babel-plugin-transform-modules-ui5.

Usage

Creating a Model

Create a new TypedModel with an underlying JSONModel by calling the constructor function and optionally provide a type:

import { TypedModel } from "ui5-typed-model";

interface Model {
  message: string;
  name: string;
  contacts: {
    name: string;
    email: string;
  }[];
}

const model = new TypedModel<Model>({
  message: "Greetings",
  name: "Universe",
  contacts: [
    { name: "Yichuan", email: "[email protected]" },
    { name: "Ryan", email: "[email protected]" },
  ],
});

// Binding the model to core for simplicity
model.bindTo(sap.ui.getCore());

You can safely get and set property values using typed path builders:

const name = model.get((data) => data.name);
// name: string

const contactEmail = model.get(
  (data) => data.contacts[0].email
);
// contactEmail: string | undefined

model.set((data) => data.message, "Hello");

Data Binding

There are convenience methods to create PropertyBindingInfo and AggregationBindingInfo objects:

import Text from "sap/m/Text";
import VBox from "sap/m/VBox";

// ...

const text = new Text();

text.bindProperty(
  "text",
  model.binding((data) => data.message)
);

const vbox = new VBox();

vbox.bindAggregation(
  "items",
  model.aggregationBinding(
    (data) => data.contacts,
    (id, model) => {
      const text = new Text(id);

      text.setBindingContext(model.context);
      text.bindProperty(
        "text",
        model.binding((_, context) => context.email)
      );

      return text;
    }
  )
);

Data Transformation

You can use map to transform bindings:

const text = new Text();

text.bindProperty(
  "text",
  model
    .binding((data) => data.message)
    .map((message) => `${message}! And Goodbye!`)
);

It is possible to create composite bindings with the helper function expressionBinding:

import { compositeBinding } from "ui5-typed-model";

// ...

const text = new Text();

text.bindProperty(
  "text",
  compositeBinding(
    [model.binding((data) => data.message), model.binding((data) => data.name)],
    (message, name) => `${message}, ${name}!`
  )
);