Skip to content

Commit

Permalink
update v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansolid committed May 7, 2019
1 parent 578739a commit c929057
Show file tree
Hide file tree
Showing 12 changed files with 784 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
src/
types/tsconfig.tsbuildinfo
rollup.config.js
*.config.js
tsconfig.json
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ Check out MobX JSX performance near the top of the charts on the [JS Frameworks

It accomplishes this with using [Babel Plugin JSX DOM Expressions](https://github.com/ryansolid/babel-plugin-jsx-dom-expressions). It compiles JSX to DOM statements and by using inner parenthesis syntax ```{( )}``` wraps expressions in functions that can be called by the library of choice. In this case autorun wrap these expressions ensuring the view stays up to date. Unlike Virtual DOM only the changed nodes are affected and the whole tree is not re-rendered over and over.

To use simply import r and wrap your code in a root:
To use simply wrap your code in a root:

```js
import { r, root } from 'mobx-jsx';
import { root } from 'mobx-jsx';

root(() => document.body.appendChild(<App />))
```

And include 'babel-plugin-jsx-dom-expressions' in your babelrc, webpack babel loader, or rollup babel plugin.

```js
"plugins": [["jsx-dom-expressions", {moduleName: 'mobx-jsx'}]]
```

# Installation

```sh
Expand Down
13 changes: 13 additions & 0 deletions dom-expressions.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
output: 'src/runtime.js',
variables: {
imports: [
`import { untracked } from 'mobx'`,
`import { root as mRoot, cleanup as mCleanup, computed as mComputed } from './core'`
],
computed: 'mComputed',
sample: 'untracked',
root: 'mRoot',
cleanup: 'mCleanup'
}
}
126 changes: 68 additions & 58 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mobx-jsx",
"description": "Raw MobX performance without the restraints of a Virtual DOM",
"version": "0.3.3",
"version": "0.4.0",
"author": "Ryan Carniato",
"license": "MIT",
"repository": {
Expand All @@ -12,19 +12,17 @@
"main": "lib/index.js",
"types": "types/index.d.ts",
"scripts": {
"build": "rollup -c && tsc",
"build": "dom-expressions && rollup -c && tsc",
"prepublishOnly": "npm run build"
},
"dependencies": {
"dom-expressions": "~0.7.7"
},
"devDependencies": {
"@babel/core": "7.4.3",
"@babel/preset-typescript": "7.3.3",
"hyper-dom-expressions": "0.7.3",
"lit-dom-expressions": "0.7.3",
"dom-expressions": "~0.8.0",
"hyper-dom-expressions": "~0.8.0",
"lit-dom-expressions": "~0.8.0",
"mobx": "^5.9.0",
"rollup": "^1.10.1",
"rollup": "^1.11.3",
"rollup-plugin-babel": "4.3.2",
"rollup-plugin-node-resolve": "4.2.3",
"typescript": "3.4.4"
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default [{
format: 'es',
file: 'dist/index.js'
}],
external: ['mobx', 'dom-expressions'],
external: ['mobx'],
plugins
}, {
input: 'src/html.ts',
Expand Down
35 changes: 35 additions & 0 deletions src/core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { autorun, untracked } from 'mobx'

type Context = { disposables: any[] };
let globalContext: Context;

export function root<T>(fn: (dispose: () => void) => T) {
let context, d: any[], ret: T;
context = globalContext;
globalContext = {
disposables: d = []
};
ret = untracked(() =>
fn(() => {
let disposable, k, len: number;
for (k = 0, len = d.length; k < len; k++) {
disposable = d[k];
disposable();
}
d = [];
})
);
globalContext = context;
return ret;
};

export function cleanup(fn: () => void) {
let ref;
(ref = globalContext) != null && ref.disposables.push(fn);
}

export function computed<T>(fn: (prev?: T) => T) {
let current: T,
dispose = autorun(() => current = fn(current));
cleanup(dispose);
}
4 changes: 2 additions & 2 deletions src/h.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createHyperScript } from 'hyper-dom-expressions';
import { r } from './index';
export * from './index';
import * as r from './index';

export { root, cleanup, selectWhen, selectEach } from './index';
export const h = createHyperScript(r);
4 changes: 2 additions & 2 deletions src/html.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createHTML } from 'lit-dom-expressions';
import { r } from './index';
export * from './index';
import * as r from './index';

export { root, cleanup, selectWhen, selectEach } from './index';
export const html = createHTML(r);
Loading

0 comments on commit c929057

Please sign in to comment.