Upgrade from Saltarelle

Geoffrey McGill edited this page Jun 21, 2017 · 42 revisions

Introduction

Remaining open issues from the Saltarelle integration.

Summary of Saltarelle tests added into main Bridge Test project available in Issue #1672.

Table Of Contents

Attributes

DefaultMemberReflectability

See Bridge Reflectable Attribute documentation.

// Saltarelle
[DefaultMemberReflectability(MemberReflectability.None)]

// Bridge
[Reflectable(false)]

IgnoreNamespace

See Bridge Namespace Attribute documentation.

// Saltarelle
[IgnoreNamespace]

// Bridge
[Namespace(false)]

Imported

See Bridge External Attribute documentation.

// Saltarelle
[Imported]

// Bridge
[External]

InlineCode

See Bridge Template Attribute documentation.

// Saltarelle
[InlineCode("code-here")]

// Bridge
[Template("code-here")]

InlineConstant

See Bridge InlineConst Attribute documentation

// Saltarelle
[InlineConstant]

// Bridge
[InlineConst]

IntrinsicProperty

See Bridge Field Attribute documentation

Treat a Property as a field in the generated JavaScript which can provide some runtime performance improvements.

In Bridge, the [Field] attribute can be applied to a Property, Class, Interface, and at the Assembly level.

Field

// Saltarelle
[IntrinsicProperty]

// Bridge
[Field]

ModuleName

See Bridge Module Attribute documentation

// Saltarelle
[ModuleName("Module1")]

// Bridge
[Module("Module1")]

Mutable

Bridge always considers Structs as mutable. This attribute is not required in Bridge.

// Saltarelle
[Mutable]

// Bridge
// no attribute required

NamedValues

See Bridge Enum Attribute documentation.

// Saltarelle
[NamedValues]

// Bridge
[Enum(Emit.Name)]

NumericValues

See Bridge Enum Attribute documentation.

// Saltarelle
[NumericValues]

// Bridge
[Enum(Emit.Value)]

Reflectable

See Bridge Reflectable Attribute documentation.

// Saltarelle
[Reflectable]

// Bridge
// By default, not required in Bridge.
// Can be used if default reflection is 
// disabled in bridge.json.

ScriptName

See Bridge Name Attribute documentation.

// Saltarelle
[ScriptName("name-here")]

// Bridge
[Name("name-here")]

Serializable

See See Bridge ObjectLiteral Attribute documentation.

// Saltarelle
[Serializable]

// Bridge
[ObjectLiteral(ObjectCreateMode.Constructor)]

ExpandParams

With Bridge, [Template({*args})] will expand the arguments.

// Saltarelle
[ExpandParams]

// Bridge
[Template("{*args}")]

DontGenerate

// Saltarelle
[DontGenerate]

// Bridge
[External]

IntrinsicProperty

Please see Issue #1229 for new real property support as of Bridge 16.0.

// Saltarelle
[IntrinsicProperty]

// Bridge
// no attribute required. 

PreserveCase

By default, the case of all entity names are preserved. The [PreserveCase] attribute is not required in Bridge.

Please see the [Convention] attribute documentation if you require changing the case of an entity.

You can also override the name of a member in Bridge by applying a custom [Name("customName")] attribute.

Also, see fileNameCasing global property which can be set in your project bridge.json configuration file.

// Saltarelle
[PreserveCase]

// Bridge
// no attribute required

Namespaces

System.Html

In C# (.NET), there is no System.Html namespace. This functionality is available in the Bridge.Html5 Assembly.

The Bridge.Html5 Assembly is installed by default, or can be added to your project by running the following command in NuGet:

Install-Package Bridge.Html5
// Saltarelle
using System.Html;

// Bridge
using Bridge.Html5;

System.Text.RegularExpressions

Saltarelle uses the JavaScript API for RegExp instead of the C# API, but was placed inside the System Namespace. Bridge uses the C# Regex API by default. The JavaScript regex API is available in Bridge.Html5.

If you want to use the C# Regex API, use System.Text.RegularExpressions. If you want to use the JavaScript RegExp API, use Bridge.Html5.

// Saltarelle
using System.Text.RegularExpressions;

// Bridge
using Bridge.Html5;

Classes

Element

// Saltarelle
Element

// Bridge
HTMLElement

ElementCollection

// Saltarelle
ElementCollection

// Bridge
HTMLCollection

Style

// Saltarelle
Style

// Bridge
CSSStyleDeclaration

TypeOption

// Saltarelle
TypeOption<T1, T2, ...>

// Bridge
Union<T1, T2, ...>

Behavior Changes

RegexMatch match

Bridge.Text.RegularExpressions.Regex.Exec returns string[] instead of RegexMatch.

// Saltarelle
RegexMatch match

// Bridge
string[] match

Concat.ToArray()

Bridge has no ToArray Method on String. This is a non-standard .NET API member.

// Saltarelle
classesName.Concat(new [] { "label" }).ToArray()

// Bridge
classesName.Concat(new [] { "label" }).As<string[]>()

arrowsOffset.Clone

Bridge returns object type. NOTE: This needs to be reviewed.

// Saltarelle
arrowsOffset.Clone()

// Bridge
arrowsOffset.Clone().As<int[]>()