carmi
CARMI - Compiler for Automatic Reactive Modelling of Inference
Last updated 3 days ago by wix-ci-publisher .
MIT · Original npm · Tarball · package.json
$ cnpm install carmi 
SYNC missed versions from official npm registry.

CARMI

Build Status

Compiler for Automatic Reactive Modelling of Inference

This is a POC of an entirely new approach to modelling inferred state, there are 4 classic methods of handling derivation of state

  1. The naive - compute from scratch every time the state is changed
  2. Handle cache invalidation manually with all the world of hurt that entails.
  3. Using Immutable data and caching computation based on the identity of the inputs
  4. Using Functional Reactive Programming to box fragments of your state with getters&setters, running derivations in a way that logs which fragments were read during the computation, and invalidate when one of their setters is invoked

This project is an attempt at a new approach, a DSL+Compiler which are fed two types of inputs:

  1. The derivation of state you need
  2. The paths in the model you want to write to

The compiler generates JS source code which handles all the reactive cache invalidation automatically

Because the compiler knows in advance all the stuff that can be read/written from/to the model, it can do all sort of cool stuff that is nearly impossible to do automatically using other approaches

  1. Track conditional consumption of parts of the model only if used with zero over head
  2. Hoisting shared sub expressions, so they are only calculated once
  3. Not track dependencies if there are no setters that can cause the expression to invalidate
  4. All computation is incremental
const { compile, root, arg0, setter, splice } = require("carmi");
const todosByIdx = root.keyBy("idx");
const anyTodoNotDone = todosByIdx.anyValues(todo => todo.get("done").not());
const todosDisplayByIdx = todosByIdx.mapValues(todo =>
  todo.get("task").plus(todo.get("done").ternary(" - done", " - not done"))
);
const todosDisplay = root.map(todo => todosDisplayByIdx.get(todo.get("idx")));
const model = {
  todosDisplay,
  anyTodoNotDone,
  setTodoDone: setter(arg0, "done"),
  spliceTodos: splice(),
};

const todosModel = eval(compile(model));
const todos = todosModel([
  { idx: "1", done: false, task: "write a blog post about carmi" },
  { idx: "2", done: true, task: "publish to npm" },
  { idx: "3", done: false, task: "write a demo for carmi" },
]);
console.log(todos.todosDisplay);
/*
[ 'write a demo for carmi - not done',
'write a blog post about carmi - not done',
'publish to npm - done' ]
*/
todos.setTodoDone(2, true); // only todosDisplayByIdx of the demo is recalculated
console.log(todos.todosDisplay);
/*
[ 'write a blog post about carmi - not done',
  'publish to npm - done',
  'write a demo for carmi - done' ]
*/
todos.spliceTodos(0, 3, todos.$model[2], todos.$model[1], todos.$model[0]); // todosDisplayByIdx is not called at all
console.log(todos.todosDisplay);
/*
[ 'write a demo for carmi - done',
  'publish to npm - done',
  'write a blog post about carmi - not done' ]
*/

Usage with Babel Macros

Using a magic comment

// @carmi

require('carmi/macro') // Activate the macro!

const { root } = require('carmi')
module.exports = { first: root.get(0) }

Using string literals

const carmi = require('carmi/macro')

const modelBuilder = carmi`
  const { root } = require('carmi')
  module.exports = { first: root.get(0) }
`

const model = modelBuilder(["first", "second"])
console.log(model.first) // prints "first"!

Usage with Babel (as a plugin)

Compiles Carmi files (xxx.carmi.js) automatically using Babel. It reserves the external modules, required by require, in order to help bundlers (like webpack) understand dependencies across Carmi models (and to help them watch the files).

// @carmi

const { root } = require("carmi");
const { second } = require("./anotherModel.carmi.js");

module.exports = { first: root.get(0), second };

turns to:

require("carmi");
require("./anotherModel.camri.js");

module.exports = CARMI_COMPILATION_RESULT;

Add to your babel configuration

Add this plugin to your .babelrc:

{
  ... babel conf ...,
  "plugins": ["carmi/babel"]
}

Now you're set! :moneybag:

Usage with Webpack

Compiles Carmi files on the fly with a fly webpack loader.

Require using webpack configurations

Add this to your webpack configurations:

module: {
  rules: [
    {
      test: /\.carmi\.js$/,
      exclude: /(node_modules|bower_components)/,
      use: {
        loader: 'carmi/loader'
      }
    }
  ]
}

Then you can just require('./model.carmi.js') like a boss

Require with explicit loader

const modelBuilder = require("carmi/loader!./model.carmi.js");
// modelBuilder is the carmi builder function!

Current Tags

364 Versions

  • 0.0.0-1a69c9bd3cf4617af027bbce95b04a65                                ...           a day ago
  • 0.0.0-c3d5cc936f1e17f04c800f79384ea18f                                ...           3 days ago
  • 1.0.229                                ...           3 days ago
  • 1.0.228                                ...           10 days ago
  • 0.0.0-c6edffa9721fd2dd3429e5e1d9541d8b                                ...           10 days ago
  • 0.0.0-c609126ab1fa20bb59e08f2b484e5609                                ...           17 days ago
  • 0.0.0-c3f303a3c35d5084f944a2a1e0c0d3f9                                ...           20 days ago
  • 0.0.0-1eec4eeca5a2ec57feb64e0aa092ef2c                                ...           20 days ago
  • 0.0.0-2a435e64f5f21db5fd7c358ec2c5e537                                ...           20 days ago
  • 1.0.227                                ...           20 days ago
  • 0.0.0-60bea30b85a5e16d5882bf730bf41c90                                ...           20 days ago
  • 1.0.226                                ...           20 days ago
  • 0.0.0-5eeb85cb679d8e304cf18828cc126672                                ...           a month ago
  • 0.0.0-00f9a04a70dc158ccb7bb349348e6e72                                ...           a month ago
  • 0.0.0-5da6363fff5d807827b26cc024d369be                                ...           a month ago
  • 1.0.225                                ...           a month ago
  • 0.0.0-e0cb18929a2ae5aaeee5b0ba74ec6d7a                                ...           a month ago
  • 1.0.224                                ...           a month ago
  • 1.0.223                                ...           a month ago
  • 0.0.0-b4577aad1524bf77986c8ee16d5fdbdb                                ...           2 months ago
  • 1.0.222                                ...           2 months ago
  • 1.0.221                                ...           2 months ago
  • 1.0.220                                ...           3 months ago
  • 1.0.219                                ...           4 months ago
  • 1.0.218                                ...           4 months ago
  • 1.0.217                                ...           4 months ago
  • 1.0.216                                ...           4 months ago
  • 1.0.215                                ...           4 months ago
  • 1.0.214                                ...           4 months ago
  • 1.0.213                                ...           4 months ago
  • 1.0.212                                ...           4 months ago
  • 1.0.211                                ...           5 months ago
  • 1.0.210                                ...           5 months ago
  • 1.0.209                                ...           5 months ago
  • 1.0.208                                ...           5 months ago
  • 1.0.207                                ...           5 months ago
  • 1.0.206                                ...           5 months ago
  • 1.0.205                                ...           5 months ago
  • 1.0.204                                ...           6 months ago
  • 1.0.203                                ...           6 months ago
  • 1.0.202                                ...           6 months ago
  • 1.0.201                                ...           6 months ago
  • 1.0.200                                ...           6 months ago
  • 1.0.199                                ...           6 months ago
  • 1.0.198                                ...           6 months ago
  • 1.0.197                                ...           6 months ago
  • 1.0.196                                ...           6 months ago
  • 1.0.195                                ...           6 months ago
  • 1.0.194                                ...           6 months ago
  • 1.0.193                                ...           6 months ago
  • 1.0.192                                ...           6 months ago
  • 1.0.191                                ...           6 months ago
  • 1.0.190                                ...           6 months ago
  • 1.0.189                                ...           6 months ago
  • 1.0.188                                ...           6 months ago
  • 1.0.187                                ...           6 months ago
  • 1.0.186                                ...           6 months ago
  • 1.0.185                                ...           6 months ago
  • 1.0.184                                ...           7 months ago
  • 1.0.183                                ...           7 months ago
  • 1.0.182                                ...           7 months ago
  • 1.0.181                                ...           7 months ago
  • 1.0.180                                ...           7 months ago
  • 1.0.179                                ...           7 months ago
  • 1.0.178                                ...           7 months ago
  • 1.0.177                                ...           7 months ago
  • 1.0.176                                ...           7 months ago
  • 1.0.175                                ...           7 months ago
  • 1.0.174                                ...           7 months ago
  • 1.0.173                                ...           7 months ago
  • 1.0.172                                ...           7 months ago
  • 1.0.171                                ...           7 months ago
  • 1.0.170                                ...           7 months ago
  • 1.0.169                                ...           7 months ago
  • 1.0.168                                ...           7 months ago
  • 1.0.167                                ...           7 months ago
  • 1.0.166                                ...           7 months ago
  • 1.0.165                                ...           7 months ago
  • 1.0.164                                ...           7 months ago
  • 1.0.163                                ...           7 months ago
  • 1.0.162                                ...           7 months ago
  • 1.0.161                                ...           7 months ago
  • 1.0.160                                ...           7 months ago
  • 1.0.159                                ...           7 months ago
  • 1.0.158                                ...           7 months ago
  • 1.0.157                                ...           7 months ago
  • 1.0.156                                ...           7 months ago
  • 1.0.155                                ...           7 months ago
  • 1.0.154                                ...           7 months ago
  • 1.0.153                                ...           7 months ago
  • 1.0.152                                ...           7 months ago
  • 1.0.151                                ...           7 months ago
  • 1.0.150                                ...           7 months ago
  • 1.0.149                                ...           7 months ago
  • 1.0.148                                ...           7 months ago
  • 1.0.147                                ...           7 months ago
  • 1.0.146                                ...           8 months ago
  • 1.0.145                                ...           8 months ago
  • 1.0.144                                ...           8 months ago
  • 1.0.143                                ...           8 months ago
  • 1.0.142                                ...           8 months ago
  • 1.0.141                                ...           8 months ago
  • 1.0.140                                ...           8 months ago
  • 1.0.139                                ...           8 months ago
  • 1.0.138                                ...           8 months ago
  • 1.0.137                                ...           8 months ago
  • 1.0.136                                ...           8 months ago
  • 1.0.135                                ...           8 months ago
  • 1.0.134                                ...           8 months ago
  • 1.0.133                                ...           8 months ago
  • 1.0.132                                ...           8 months ago
  • 1.0.131                                ...           8 months ago
  • 1.0.130                                ...           8 months ago
  • 1.0.129                                ...           8 months ago
  • 1.0.128                                ...           8 months ago
  • 1.0.127                                ...           8 months ago
  • 1.0.126                                ...           8 months ago
  • 1.0.125                                ...           8 months ago
  • 1.0.124                                ...           8 months ago
  • 1.0.123                                ...           8 months ago
  • 1.0.122                                ...           8 months ago
  • 1.0.121                                ...           8 months ago
  • 1.0.120                                ...           8 months ago
  • 1.0.119                                ...           8 months ago
  • 1.0.118                                ...           8 months ago
  • 1.0.117                                ...           8 months ago
  • 1.0.116                                ...           8 months ago
  • 1.0.115                                ...           8 months ago
  • 1.0.114                                ...           8 months ago
  • 1.0.113                                ...           8 months ago
  • 1.0.112                                ...           8 months ago
  • 1.0.111                                ...           8 months ago
  • 1.0.110                                ...           8 months ago
  • 1.0.109                                ...           8 months ago
  • 1.0.108                                ...           8 months ago
  • 1.0.107                                ...           8 months ago
  • 1.0.106                                ...           8 months ago
  • 1.0.105                                ...           8 months ago
  • 1.0.104                                ...           8 months ago
  • 1.0.103                                ...           8 months ago
  • 1.0.102                                ...           8 months ago
  • 1.0.101                                ...           8 months ago
  • 1.0.100                                ...           8 months ago
  • 1.0.99                                ...           8 months ago
  • 1.0.98                                ...           8 months ago
  • 1.0.97                                ...           8 months ago
  • 1.0.96                                ...           8 months ago
  • 1.0.95                                ...           8 months ago
  • 1.0.94                                ...           8 months ago
  • 1.0.93                                ...           8 months ago
  • 1.0.92                                ...           8 months ago
  • 1.0.91                                ...           8 months ago
  • 1.0.90                                ...           8 months ago
  • 1.0.89                                ...           8 months ago
  • 1.0.88                                ...           8 months ago
  • 1.0.87                                ...           8 months ago
  • 1.0.86                                ...           8 months ago
  • 1.0.85                                ...           8 months ago
  • 1.0.84                                ...           8 months ago
  • 1.0.83                                ...           8 months ago
  • 1.0.82                                ...           8 months ago
  • 1.0.81                                ...           8 months ago
  • 1.0.80                                ...           8 months ago
  • 1.0.79                                ...           8 months ago
  • 1.0.78                                ...           8 months ago
  • 1.0.77                                ...           8 months ago
  • 1.0.76                                ...           9 months ago
  • 1.0.75                                ...           9 months ago
  • 1.0.74                                ...           9 months ago
  • 1.0.73                                ...           9 months ago
  • 1.0.72                                ...           9 months ago
  • 1.0.71                                ...           9 months ago
  • 1.0.70                                ...           9 months ago
  • 1.0.69                                ...           9 months ago
  • 1.0.68                                ...           9 months ago
  • 1.0.67                                ...           9 months ago
  • 1.0.66                                ...           9 months ago
  • 1.0.65                                ...           9 months ago
  • 1.0.64                                ...           9 months ago
  • 1.0.63                                ...           9 months ago
  • 1.0.62                                ...           9 months ago
  • 1.0.61                                ...           9 months ago
  • 1.0.60                                ...           9 months ago
  • 1.0.59                                ...           9 months ago
  • 1.0.58                                ...           9 months ago
  • 1.0.57                                ...           9 months ago
  • 1.0.56                                ...           9 months ago
  • 1.0.55                                ...           9 months ago
  • 1.0.54                                ...           9 months ago
  • 1.0.53                                ...           9 months ago
  • 1.0.52                                ...           9 months ago
  • 1.0.51                                ...           9 months ago
  • 1.0.50                                ...           9 months ago
  • 1.0.49                                ...           9 months ago
  • 1.0.48                                ...           9 months ago
  • 1.0.47                                ...           9 months ago
  • 1.0.46                                ...           9 months ago
  • 1.0.45                                ...           9 months ago
  • 1.0.44                                ...           9 months ago
  • 1.0.43                                ...           9 months ago
  • 1.0.42                                ...           9 months ago
  • 1.0.41                                ...           9 months ago
  • 1.0.40                                ...           9 months ago
  • 1.0.39                                ...           9 months ago
  • 1.0.38                                ...           9 months ago
  • 1.0.37                                ...           9 months ago
  • 1.0.36                                ...           9 months ago
  • 1.0.35                                ...           9 months ago
  • 1.0.34                                ...           9 months ago
  • 1.0.33                                ...           9 months ago
  • 1.0.32                                ...           9 months ago
  • 1.0.31                                ...           9 months ago
  • 1.0.30                                ...           9 months ago
  • 1.0.29                                ...           9 months ago
  • 1.0.28                                ...           9 months ago
  • 1.0.27                                ...           9 months ago
  • 1.0.26                                ...           9 months ago
  • 1.0.25                                ...           9 months ago
  • 1.0.24                                ...           9 months ago
  • 1.0.23                                ...           9 months ago
  • 1.0.22                                ...           9 months ago
  • 1.0.21                                ...           9 months ago
  • 1.0.20                                ...           9 months ago
  • 1.0.19                                ...           9 months ago
  • 1.0.18                                ...           9 months ago
  • 1.0.17                                ...           9 months ago
  • 1.0.16                                ...           9 months ago
  • 1.0.15                                ...           9 months ago
  • 1.0.14                                ...           9 months ago
  • 1.0.13                                ...           10 months ago
  • 1.0.12                                ...           10 months ago
  • 1.0.11                                ...           10 months ago
  • 1.0.10                                ...           10 months ago
  • 1.0.9                                ...           10 months ago
  • 1.0.8                                ...           10 months ago
  • 1.0.7                                ...           10 months ago
  • 1.0.6                                ...           10 months ago
  • 1.0.5                                ...           10 months ago
  • 1.0.4                                ...           10 months ago
  • 1.0.3                                ...           10 months ago
  • 1.0.2                                ...           10 months ago
  • 1.0.1                                ...           10 months ago
  • 1.0.0                                ...           10 months ago
  • 0.2.17                                ...           10 months ago
  • 0.2.16                                ...           10 months ago
  • 0.2.15                                ...           10 months ago
  • 0.2.14                                ...           10 months ago
  • 0.2.13                                ...           10 months ago
  • 0.2.12                                ...           10 months ago
  • 0.2.11                                ...           10 months ago
  • 0.2.10                                ...           10 months ago
  • 0.2.9                                ...           10 months ago
  • 0.2.8                                ...           10 months ago
  • 0.2.7                                ...           10 months ago
  • 0.2.6                                ...           10 months ago
  • 0.2.5                                ...           10 months ago
  • 0.2.4                                ...           10 months ago
  • 0.2.3                                ...           10 months ago
  • 0.2.2                                ...           10 months ago
  • 0.2.1                                ...           10 months ago
  • 0.2.0                                ...           10 months ago
  • 0.1.68                                ...           10 months ago
  • 0.1.67                                ...           10 months ago
  • 0.1.66                                ...           10 months ago
  • 0.1.65                                ...           10 months ago
  • 0.1.64                                ...           10 months ago
  • 0.1.63                                ...           10 months ago
  • 0.1.62                                ...           10 months ago
  • 0.1.61                                ...           10 months ago
  • 0.1.60                                ...           10 months ago
  • 0.1.59                                ...           10 months ago
  • 0.1.58                                ...           10 months ago
  • 0.1.57                                ...           a year ago
  • 0.1.56                                ...           a year ago
  • 0.1.55                                ...           a year ago
  • 0.1.54                                ...           a year ago
  • 0.1.53                                ...           a year ago
  • 0.1.52                                ...           a year ago
  • 0.1.51                                ...           a year ago
  • 0.1.50                                ...           a year ago
  • 0.1.49                                ...           a year ago
  • 0.1.48                                ...           a year ago
  • 0.1.47                                ...           a year ago
  • 0.1.46                                ...           a year ago
  • 0.1.45                                ...           a year ago
  • 0.1.44                                ...           a year ago
  • 0.1.43                                ...           a year ago
  • 0.1.42                                ...           a year ago
  • 0.1.41                                ...           a year ago
  • 0.1.40                                ...           a year ago
  • 0.1.39                                ...           a year ago
  • 0.1.38                                ...           a year ago
  • 0.1.37                                ...           a year ago
  • 0.1.36                                ...           a year ago
  • 0.1.35                                ...           a year ago
  • 0.1.34                                ...           a year ago
  • 0.1.33                                ...           a year ago
  • 0.1.32                                ...           a year ago
  • 0.1.31                                ...           a year ago
  • 0.1.30                                ...           a year ago
  • 0.1.29                                ...           a year ago
  • 0.1.28                                ...           a year ago
  • 0.1.27                                ...           a year ago
  • 0.1.26                                ...           a year ago
  • 0.1.25                                ...           a year ago
  • 0.1.24                                ...           a year ago
  • 0.1.23                                ...           a year ago
  • 0.1.22                                ...           a year ago
  • 0.1.21                                ...           a year ago
  • 0.1.20                                ...           a year ago
  • 0.1.19                                ...           a year ago
  • 0.1.18                                ...           a year ago
  • 0.1.17                                ...           a year ago
  • 0.1.16                                ...           a year ago
  • 0.1.15                                ...           a year ago
  • 0.1.14                                ...           a year ago
  • 0.1.13                                ...           a year ago
  • 0.1.12                                ...           a year ago
  • 0.1.11                                ...           a year ago
  • 0.1.10                                ...           a year ago
  • 0.1.9                                ...           a year ago
  • 0.1.8                                ...           a year ago
  • 0.1.7                                ...           a year ago
  • 0.1.6                                ...           a year ago
  • 0.1.5                                ...           a year ago
  • 0.1.4                                ...           a year ago
  • 0.1.3                                ...           a year ago
  • 0.1.2                                ...           a year ago
  • 0.1.1                                ...           a year ago
  • 0.1.0                                ...           a year ago
  • 0.0.34                                ...           a year ago
  • 0.0.33                                ...           a year ago
  • 0.0.32                                ...           a year ago
  • 0.0.31                                ...           a year ago
  • 0.0.30                                ...           a year ago
  • 0.0.29                                ...           a year ago
  • 0.0.28                                ...           a year ago
  • 0.0.27                                ...           a year ago
  • 0.0.26                                ...           a year ago
  • 0.0.25                                ...           a year ago
  • 0.0.24                                ...           a year ago
  • 0.0.23                                ...           a year ago
  • 0.0.22                                ...           a year ago
  • 0.0.21                                ...           a year ago
  • 0.0.20                                ...           a year ago
  • 0.0.19                                ...           a year ago
  • 0.0.18                                ...           a year ago
  • 0.0.17                                ...           a year ago
  • 0.0.16                                ...           a year ago
  • 0.0.15                                ...           a year ago
  • 0.0.14                                ...           a year ago
  • 0.0.13                                ...           a year ago
  • 0.0.12                                ...           a year ago
  • 0.0.11                                ...           a year ago
  • 0.0.10                                ...           a year ago
  • 0.0.9                                ...           a year ago
  • 0.0.8                                ...           a year ago
  • 0.0.7                                ...           a year ago
  • 0.0.6                                ...           a year ago
  • 0.0.5                                ...           a year ago
  • 0.0.4                                ...           a year ago
  • 0.0.3                                ...           a year ago
  • 0.0.2                                ...           a year ago
  • 0.0.1                                ...           a year ago
Downloads
Today 26
This Week 890
This Month 1,134
Last Day 228
Last Week 244
Last Month 1,745
Dependencies (29)
Dev Dependencies (10)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |