Skip to content

Commit 7167fd2

Browse files
committed
feat: initial commit, RuntimeCompiler working
0 parents  commit 7167fd2

17 files changed

+9305
-0
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["react-native"]
3+
}

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[*]
2+
indent_size = 2
3+
indent_style = space

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
**/__tests__
2+
**/__snapshots__
3+
**/*.test.js
4+
.vscode

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"editor.formatOnSave": true
3+
}

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# animated-expr
2+
3+
A tiny language for arithmetic over React Native's [Animated](https://facebook.github.io/react-native/docs/animations.html) values.
4+
5+
| JS | `animated-expr` |
6+
| ------------------------------------------- | --------------------------- |
7+
| `Animated.add(x, y)` | `` animated`${x} + ${y}` `` |
8+
| `Animated.multiply(x, y)` | `` animated`${x} * ${y}` `` |
9+
| `Animated.divide(x, y)` | `` animated`${x} / ${y}` `` |
10+
| `Animated.add(x, Animated.multiply(-1, y))` | `` animated`${x} - ${y}` `` |
11+
| `Animated.modulo(x, y)` | `` animated`${x} % ${y}` `` |
12+
13+
## Sample code
14+
15+
```js
16+
import { Animated } from "react-native";
17+
import animated from "animated-expr";
18+
19+
const a = new Animated.Value(1);
20+
const b = animated`1 / ${a}`;
21+
22+
Animated.spring(a, { toValue: 2 }).start();
23+
```
24+
25+
## Getting started
26+
27+
The recommended way of using this package is at compile time, via the included Babel plugin. Otherwise, you will end up compiling expressions at runtime, which is slower and likely not what you want for real-world use.
28+
29+
First, install the package:
30+
31+
```sh
32+
npm install --save-dev animated-expr
33+
```
34+
35+
Then, set up the Babel plugin by adding it to the `plugins` array in your `.babelrc` file. (If you don't have a `.babelrc` file yet, [read this](https://github.com/facebook/react-native/tree/master/babel-preset).)
36+
37+
#### .babelrc
38+
39+
```json
40+
{
41+
"presets": ["react-native"],
42+
"plugins": ["animated-expr/babel"]
43+
}
44+
```

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require("./src/index");

jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
preset: "react-native"
3+
};

0 commit comments

Comments
 (0)