All Projects → insin → Msx

insin / Msx

Licence: other
JSX for Mithril.js 0.x

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Msx

React Axe
[DEPRECATED] Accessibility auditing for React.js applications
Stars: ✭ 1,201 (+224.59%)
Mutual labels:  deprecated, unmaintained
Cudlr
⛔️ [DEPRECATED] Console for Unity Debugging and Logging Remotely
Stars: ✭ 167 (-54.86%)
Mutual labels:  deprecated, unmaintained
Vagrant Librarian Chef
*UNMAINTAINED* A Vagrant plugin to install Chef cookbooks using Librarian-Chef.
Stars: ✭ 80 (-78.38%)
Mutual labels:  deprecated, unmaintained
Framework7 With Angularjs Demo App
⛔️ Unmaintained and deprecated!
Stars: ✭ 81 (-78.11%)
Mutual labels:  deprecated, unmaintained
jade-babel
Jade plugin for Babel
Stars: ✭ 39 (-89.46%)
Mutual labels:  deprecated, unmaintained
Miniproxy
🚨⚠️ UNMAINTAINED! ⚠️🚨 A simple PHP web proxy.
Stars: ✭ 810 (+118.92%)
Mutual labels:  deprecated, unmaintained
Tgcameraviewcontroller
Custom camera with AVFoundation. Beautiful, light and easy to integrate with iOS projects.
Stars: ✭ 1,432 (+287.03%)
Mutual labels:  deprecated, unmaintained
Axe Cli
[Deprecated] A command-line interface for the aXe accessibility testing engine
Stars: ✭ 419 (+13.24%)
Mutual labels:  deprecated, unmaintained
cleverbot
Deprecated/unmaintained. See https://www.cleverbot.com/api/
Stars: ✭ 23 (-93.78%)
Mutual labels:  deprecated, unmaintained
passion
An object-oriented LÖVE game engine
Stars: ✭ 35 (-90.54%)
Mutual labels:  deprecated, unmaintained
django-snow
ServiceNow Ticket Management App for Django based projects
Stars: ✭ 16 (-95.68%)
Mutual labels:  deprecated, unmaintained
Deprecated Mapbox Ios Sdk
REPLACED – use https://www.mapbox.com/ios-sdk instead
Stars: ✭ 325 (-12.16%)
Mutual labels:  deprecated, unmaintained
addon-sdk-content-scripts
DEPRECATED | Use WebExtensions instead | Add-ons demonstrating how to use content scripts in the Add-on SDK.
Stars: ✭ 23 (-93.78%)
Mutual labels:  deprecated, unmaintained
React Heatpack
A 'heatpack' command for quick React development with webpack hot reloading
Stars: ✭ 354 (-4.32%)
Mutual labels:  deprecated, unmaintained
Redditkit
An Objective-C wrapper for the reddit API
Stars: ✭ 299 (-19.19%)
Mutual labels:  unmaintained
Wpaint
jQuery Paint Plugin
Stars: ✭ 332 (-10.27%)
Mutual labels:  deprecated
Sucrase
Super-fast alternative to Babel for when you can target modern JS runtimes
Stars: ✭ 4,436 (+1098.92%)
Mutual labels:  jsx
Dukpy
Simple JavaScript interpreter for Python
Stars: ✭ 296 (-20%)
Mutual labels:  jsx
Scaleapp
scaleApp is a JavaScript framework for scalable and maintainable One-Page-Applications
Stars: ✭ 353 (-4.59%)
Mutual labels:  unmaintained
H5ive Deprecated
**DEPRECATED** A collection of thin facade APIs wrapped around HTML5 JavaScript features.
Stars: ✭ 332 (-10.27%)
Mutual labels:  deprecated

DEPRECATED

As of Mithril.js v1.0.0, you can use the react-transform-jsx Babel plugin for JSX.

See Mithril.js' JSX documentation for details.


MSX Build Status

MSX is based on version 0.13.2 of React's JSX Transformer

MSX tweaks React's JSX Transformer to output contents compatible with Mithril's m.render() function, allowing you to use HTML-like syntax in your Mithril view code, like this:

var todos = ctrl.list.map(function(task, index) {
  return <li className={task.completed() && 'completed'}>
    <div className="view">
      <input
        className="toggle"
        type="checkbox"
        onclick={m.withAttr('checked', task.completed)}
        checked={task.completed()}
      />
      <label>{task.title()}</label>
      <button className="destroy" onclick={ctrl.remove.bind(ctrl, index)}/>
    </div>
    <input className="edit"/>
  </li>
})

HTML tags and custom elements

For tag names which look like HTML elements or custom elements (lowercase, optionally containing hyphens), raw virtual DOM objects - matching the VirtualElement signature accepted by m.render() - will be generated by default.

Input:

<div id="example">
  <h1>Test</h1>
  <my-element name="test"/>
</div>

Output:

{tag: "div", attrs: {id:"example"}, children: [
  {tag: "h1", attrs: {}, children: ["Test"]},
  {tag: "my-element", attrs: {name:"test"}}
]}

This effectively precompiles your view code for a slight performance tweak.

Mithril components

Otherwise, it's assumed a tag name is a reference to an in-scope variable which is a Mithril component.

Passing attributes or children to a component will generate a call to Mithril's m.component() function, with children always being passed as an Array:

Input:

<form>
  {/* Bare component */}
  <Uploader/>
  {/* Component with attributes */}
  <Uploader onchange={ctrl.files}/>
  {/* Component with attributes and children */}
  <Uploader onchange={ctrl.files}>
    {ctrl.files().map(file => <File {...file}/>)}
  </Uploader>
  <button type="button" onclick={ctrl.save}>Upload</button>
</form>

Output:

{tag: "form", attrs: {}, children: [
  /* Bare component */
  Uploader,
  /* Component with attributes */
  m.component(Uploader, {onchange:ctrl.files}),
  /* Component with attributes and children */
  m.component(Uploader, {onchange:ctrl.files}, [
    ctrl.files().map(function(file)  {return m.component(File, Object.assign({},  file));})
  ]),
  {tag: "button", attrs: {type:"button", onclick:ctrl.save}, children: ["Upload"]}
]}

MSX assumes your component's (optional) controller() and (required) view() functions have the following signatures, where attributes is an Object and children is an Array:

controller([attributes[, children]])
view(ctrl[, attributes[, children]])

As such, if a component has children but no attributes, an empty attributes object will still be passed:

Input:

<Field>
  <input onchange={m.withAttr('value', ctrl.description)} value={ctrl.description()}/>
</Field>

Output:

m.component(Field, {}, [
  {tag: "input", attrs: {onchange:m.withAttr('value', ctrl.description), value:ctrl.description()}}
])

JSX spread attributes and Object.assign()

If you make use of JSX Spread Attributes, the resulting code will make use of Object.assign() to merge attributes - if your code needs to run in environments which don't implement Object.assign() natively, you're responsible for ensuring it's available via a shim, or otherwise.

Other than that, the rest of React's JSX documentation should still apply:

In-browser JSX Transform

For development and quick prototyping, an in-browser MSX transform is available.

Download or use it directly from cdn.rawgit.com:

Include a <script type="text/msx"> tag to engage the MSX transformer.

To enable ES6 transforms, use <script type="text/msx;harmony=true">. Check out the source of the live example of using in-browser JSX + ES6 transforms.

Here's a handy template you can use:

<meta charset="UTF-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/mithril/0.2.0/mithril.js"></script>
<script src="https://cdn.rawgit.com/insin/msx/master/dist/MSXTransformer.js"></script>
<div id="app"></div>
<script type="text/msx;harmony=true">void function() { 'use strict';

var Hello = {
  controller() {
    this.who = m.prop('World')
  },

  view(ctrl) {
    return <h1>Hello {ctrl.who()}!</h1>
  }
}

m.mount(document.getElementById('app'), Hello)

}()</script>

Command Line Usage

npm install -g msx
msx --watch src/ build/

To disable precompilation from the command line, pass a --no-precompile flag.

Run msx --help for more information.

Module Usage

npm install msx
var msx = require('msx')

Module API

msx.transform(source: String[, options: Object])

Transforms XML-like syntax in the given source into object literals compatible with Mithril's m.render() function, or to function calls using Mithril's m() function, returning the transformed source.

To enable ES6 transforms supported by JSX Transformer, pass a harmony option:

msx.transform(source, {harmony: true})

To disable default precompilation and always output m() calls, pass a precompile option:

msx.transform(source, {precompile: false})

Examples

Example inputs (using some ES6 features) and outputs are in test/jsx and test/js, respectively.

An example gulpfile.js is provided, which implements an msxTransform() step using msx.transform().

Related Modules

MIT Licensed

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].