Skip to content

Commit

Permalink
rewrite using cycle/react
Browse files Browse the repository at this point in the history
  • Loading branch information
staltz committed Jul 12, 2018
1 parent cb5e191 commit e5daac2
Show file tree
Hide file tree
Showing 23 changed files with 623 additions and 523 deletions.
7 changes: 0 additions & 7 deletions .editorconfig

This file was deleted.

1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

7 changes: 0 additions & 7 deletions .eslintrc

This file was deleted.

26 changes: 6 additions & 20 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
# Editor-specific
.idea
*.sublime-project
*.sublime-workspace
.settings

# Installed libs
/.vscode
/lib
/coverage
node_modules

# Generated
test/browser/page/tests-bundle.js
lib/

# Secrets
.zuulrc

# Misc
ignore
npm-debug.log
ts/*
!ts/cycle.d.ts
package-lock.json
shrinkwrap.yaml
yarn.lock
15 changes: 10 additions & 5 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
examples/
ignore/
.idea/
*.sublime-project
*.sublime-workspace
/.vscode
/src
/test
/coverage
.gitignore
node_modules
package-lock.json
shrinkwrap.yaml
yarn.lock
tsconfig.json
7 changes: 0 additions & 7 deletions CONTRIBUTING.md

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Andre Medeiros
Copyright (c) 2018 Andre 'Staltz' Medeiros

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
64 changes: 0 additions & 64 deletions README.md

This file was deleted.

25 changes: 0 additions & 25 deletions docs/api.md

This file was deleted.

72 changes: 42 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,51 @@
{
"name": "@cycle/react-native",
"version": "1.0.0-experimental.15",
"description": "A Cycle.js Driver for interacting with React Native",
"main": "lib/index.js",
"author": "Andre Staltz",
"version": "1.0.0",
"description": "Cycle.js driver that uses React Native to render",
"author": "Andre Staltz <contact@staltz.com>",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/cyclejs/cycle-react-native"
},
"peerDependencies": {
"rx": ">=3",
"react-native": "~0.24.0"
"bugs": "https://github.com/cyclejs/react-native/issues",
"repository": "https://github.com/cyclejs/react-native/tree/master",
"keywords": [
"react",
"cyclejs",
"xstream",
"mvi",
"react-native",
"driver"
],
"main": "lib/cjs/index.js",
"typings": "lib/cjs/index.d.ts",
"types": "lib/cjs/index.d.ts",
"dependencies": {
"@cycle/react": "^1.0.2",
"react": "16.4.x",
"react-native": ">=0.55.0",
"xstream": "11.x.x"
},
"devDependencies": {
"rx": ">=3",
"react-native": "~0.24.0",
"babel": "5.8.x",
"eslint": "1.0.x",
"eslint-config-cycle": "3.0.x",
"eslint-plugin-cycle": "1.0.x",
"eslint-plugin-no-class": "0.1.x",
"markdox": "0.1.9"
"@cycle/run": "^4.4.0",
"@types/mocha": "^2.2.40",
"@types/node": "^10.5.2",
"@types/react": "16.4.x",
"@types/react-native": "0.55.x",
"@types/react-test-renderer": "^16.0.1",
"@huston007/react-native-mock": "^0.3.3",
"mocha": "^5.2.0",
"react-test-renderer": "16.4.1",
"ts-node": "^7.0.0",
"typescript": "2.6.x",
"babel-cli": "^6.24.0",
"babel-preset-react-native": "4.0.0"
},
"publishConfig": {
"access": "public"
},
"scripts": {
"eslint": "eslint src/",
"test": "npm run eslint",
"test-ci": "npm run eslint",
"precompile-lib": "rm -rf lib/ && mkdir -p lib",
"compile-lib": "babel -d lib/ src/",
"docs": "node ./scripts/make-api-docs.js",
"prepublish": "npm run compile-lib",
"release": "npm run release-patch",
"release-patch": "git checkout master && npm version patch && git push origin master --tags && npm publish --access=public",
"release-minor": "git checkout master && npm version minor && git push origin master --tags && npm publish --access=public",
"release-major": "git checkout master && npm version major && git push origin master --tags && npm publish --access=public"
"prepublishOnly": "npm run compile",
"compile": "npm run compile-cjs && npm run compile-es6",
"compile-cjs": "tsc --module commonjs --outDir ./lib/cjs",
"compile-es6": "echo 'TODO' : tsc --module es6 --outDir ./lib/es6",
"test": "TS_NODE_PROJECT=test/tsconfig.json mocha test/*.ts --require @huston007/react-native-mock/mock.js --require ts-node/register --recursive"
}
}
80 changes: 80 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Cycle React Native

> Cycle.js driver that uses React Native to render
- Provides a driver factory `makeReactNativeDriver`
- Contains hyperscript helper functions, such as `View()`, `Text()`, etc

## Example

```js
import xs from 'xstream';
import {run} from '@cycle/run';
import {makeReactNativeDriver, TouchableOpacity, View, Text} from '@cycle/react-native';

function main(sources) {
const inc$ = sources.react.select('inc').events('click');

const count$ = inc$.fold(count => count + 1, 0);

const elem$ = count$.map(i =>
TouchableOpacity('inc', [
View([
Text(`Counter: ${i}`),
])
]),
);

return {
react: elem$,
};
}

run(main, {
react: makeReactNativeDriver('MyApp')),
});
```

## Installation

Start by installing React Native prerequisites (XCode, react-native-cli, watchman).

Then create a React Native project using the CLI.

When the project is set up, npm install `@cycle/react-native`, `@cycle/run`, and a stream library like `xstream`, then replace the index.js with something that looks like the example code in this readme.

## API

### `makeReactNativeDriver(appKey)`

Returns a driver that uses React Native to render your Cycle.js app in the native application known by the string `appKey`.

### Hyperscript helpers

Import hyperscript helpers such as `View`, `Text`, `TouchableOpacity`, etc to create React elements to represent the respective built-in native components: `<View>`, `<Text>`, `<TouchableOpacity>`, etc.

The basic usage is `View(props, children)`, but some variations and shortcuts are allowed:

- `View()` becomes `<View/>`
- `View(propsObject)` becomes `<View {...props}></View>`
- `Text('text content')` becomes `<Text>text content</Text>`
- `View([child1, child2])`
- `Text(propsObject, 'text content')`
- `View(propsObject, [child1, child2])`
- etc

There are also shortcuts for (MVI) intent selectors:

- `Touchable('inc')` becomes `h(Touchable, {selector: 'inc'})`
- `Touchable('inc', propsObject)` becomes `h(Touchable, {selector: 'inc', ...props})`
- `Text('myselector', 'text content')`
- `Touchable('inc', [child])`
- `Touchable('inc', propsObject, [child])`
- etc

For non-built-in components (e.g. third party) components, you can use `h(ThirdPartyComponent)` with `h` from `@cycle/react` or you can build a helper using `makeHelper(ThirdPartyComponent)` with `makeHelper` from `@cycle/react-native`.

## License

MIT, Andre 'Staltz' Medeiros 2018

52 changes: 0 additions & 52 deletions scripts/cycle-docs-template.md.ejs

This file was deleted.

Loading

0 comments on commit e5daac2

Please sign in to comment.