Socket
Socket
Sign inDemoInstall

@servicenow/ui-core

Package Overview
Dependencies
62
Maintainers
6
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @servicenow/ui-core

Core package of the UI Framework on Next Experience


Version published
Weekly downloads
129
increased by86.96%
Maintainers
6
Install size
6.87 MB
Created
Weekly downloads
 

Readme

Source

@servicenow/ui-core

createCustomElement

Define a custom element.

ParamTypeDescription
elementNamestringThe tag name of the custom element.
configObjectThe custom element configuration.
[config.setInitialState]functionFunction that returns the initial state for a component.
[config.properties]ObjectThe properties used by a custom element.
config.properties.nameObjectThe name of the property.
[config.properties.name.default]*The default value of the property.
[config.properties.name.computed]functionA function that computes the property value.
config.properties.name.computed.stateObjectThe custom element state.
[config.properties.name.onChange]functionA function that will be called with the new property value, the previous value, and the dispatch function.
[config.properties.name.reflect]booleanReflect property change to corresponding attribute.
[config.properties.name.unstableParse]booleanParse attribute values when corresponding properties are set.
[config.properties.name.readOnly]booleanProperty cannot be externally set.
[config.actions]ObjectThe actions the custom element dispatches.
config.actions.typeObjectThe action type, name.
[config.actions.private]booleanIndicates if the action is visible outside of the custom element.
[config.actions.handlers]ArrayEffect handlers to run when the action type is dispatched.
config.rendererObjectThe renderer to be used by the custom element.
config.renderer.typefunctionThe library that renders the view.
config.renderer.viewfunctionA function that is executed by onStateChange.
[config.renderer.transformState]functionA function that executes before a component's state is passed to the handler.
[config.onDisconnect]functionA function that executes when the custom element is disconnected.
[config.onConnect]functionA function that executes when the custom element is connected.
[config.behaviors]ArrayBehaviors to applied to the custom element.

Example

import {createCustomElement} from '@servicenow/ui-core';
import snabbdom from '@servicenow/ui-renderer-snabbdom';

createCustomElement('sn-hello-world', {
	properties: {
		name: {
			default: 'Fred'
		}
	},
	renderer: {
		type: snabbdom,
		transformState({properties}) {
			return properties;
		},
		view: ({name}) => {
			return <p>Hello {name}!</p>;
		}
	}
});

Action Routing

Actions will "bubble" up the component hierarchy unless they are explictly stopped by dispatch meta data, {stopPropagtion: true}, or part of the stopPropagtion configuration for a component definition.

dispatch('SOMETHING_HAPPENED', {somethingHappened: true}, {stopPropagtion: true});

OR

createCustomElement('sn-foo', () => null, {
	stopPropagtion: ['SOMETHING_HAPPENED']
});

FAQs

Last updated on 04 Aug 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc