Skip to content

Commit

Permalink
Reactive Hooks and Updates (v9.0.0, #135)
Browse files Browse the repository at this point in the history
  • Loading branch information
JRJurman authored Dec 24, 2019
1 parent 2350d60 commit 84c1ee3
Show file tree
Hide file tree
Showing 117 changed files with 1,744 additions and 4,340 deletions.
8 changes: 6 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
build:
docker:
# specify the version you desire here
- image: circleci/node:10-browsers
- image: circleci/node:latest

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
Expand Down Expand Up @@ -37,6 +37,10 @@ jobs:

- run: npm run test:ci

- store_artifacts:
path: coverage/lcov-report/

- run: npm run build

- run: npm run integration-test
- store_artifacts:
path: dist
23 changes: 14 additions & 9 deletions configs/docma.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"src": [
"./src/**/*.doc.js",
"./src/**/*.js",
"./docs/guides/*.md"
],
],
"jsdoc": {
},
"app": {
"title": "Tram-One",
"entrance": "content:introduction",
Expand Down Expand Up @@ -44,6 +46,9 @@
"options": {
"title": "Tram-One",
"logo": "./images/logo_64.png",
"sidebar": {
"toolbar": false
},
"navbar": {
"enabled": true,
"fixed": true,
Expand All @@ -54,20 +59,20 @@
"label": "Introduction",
"href": "/"
},
{
"label": "Tutorial",
"href": "/tutorial"
},
{
"label": "API",
"href": "/api/#Tram-One"
"href": "/api"
},
{
"label": "Cheatsheet",
"href": "/cheat-sheet"
},
{
"label": "Try It",
"items": [
{
"label": "CodeSandbox",
"href": "https://codesandbox.io/s/github/Tram-One/tram-one-express/tree/tram-one-example",
"label": "StackBlitz",
"href": "https://stackblitz.com/edit/tram-one-blank-template?file=index.js",
"target": "_blank"
},
{
Expand Down
9 changes: 8 additions & 1 deletion configs/rollup.config.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@ const commonjs = require('rollup-plugin-commonjs')
const pkg = require('../package.json')

const external = Object.keys(pkg.dependencies)
.concat([
'type/function/ensure',
'type/object/ensure',
'type/string/ensure',
'type/value/ensure'
])

const plugins = [
commonjs(),
filesize()
]

export default {
input: 'src/tram-one/index.js',
input: 'src/tram-one',
external,
plugins,
output: {
file: pkg.commonjs,
exports: 'named',
format: 'cjs',
interop: false
}
Expand Down
3 changes: 2 additions & 1 deletion configs/rollup.config.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ const plugins = [
// domino is a package used by belit to support server side rendering,
// it does not need to be included in browser buidls, which will have document
export default {
input: 'src/tram-one/index.js',
input: 'src/tram-one',
external: ['domino'],
output: {
name: 'tram-one',
exports: 'named',
file: pkg.umd,
globals: { domino: 'domino' },
format: 'umd'
Expand Down
4 changes: 2 additions & 2 deletions docs/badges/cjs.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/badges/umd.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
133 changes: 133 additions & 0 deletions docs/guides/cheat-sheet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Tram-One Cheatsheet

<style>
pre code {
font-size: 66.4%;
}
ul {
padding-left: 22px;
}
pre {
overflow-x: hidden;
margin-bottom: 0px;
}
.sheet-block {
flex-grow: 1;
margin: 1em;
font-size: 0.8em;
}
.cheat-sheet {
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
}
</style>

<div class="cheat-sheet">

<div class="sheet-block">

#### New Component
```javascript
const html = registerHtml()
const CustomList = (props, children) => {
return html`
<div>
${props.title}
<ul>${children}</ul>
</div>
`
}
```
* Takes props and children

</div>

<div class="sheet-block">

#### Using Components
```javascript
import List from './List'
const html = registerHtml({
'tram-list': List
})
```
* tag-name is used in `html`
* can be be `List` like React
* can be non-hyphanated, `list`

</div>

<div class="sheet-block">

#### Component State
```javascript
const [ color, setColor ] = useObservable('blue')
const toggleColor = () => setColor('red')
```
* initial state can be an object or array
* avoid using setter if managing an object or array

</div>

<div class="sheet-block">

#### Global State
```javascript
const [ list, setList ] = useGlobalObservable('todos', [])
const onAddItem = newItem => list.push(newItem)
```
* not all calls need an initial value

</div>

<div class="sheet-block">

#### Testing Routes
```javascript
if (useUrlParams('/about')) return html`<about />`
if (useUrlParams('/api')) return html`<api />`
return html`<home-page />`
```
* mismatched route returns false
* matched route returns object

</div>

<div class="sheet-block">

#### Route Parameters
```javascript
const { accountId } = useUrlParams('/:accountId/')
```
* also reads query params

</div>
<div class="sheet-block">

#### Effects
```javascript
useEffect(() => {
document.title = "Tram-One Page"
return () => console.log('cleanup triggered')
})
```
* calls for every component re-render

</div>

<div class="sheet-block">

#### Async Effects
```javascript
const [user] = useObservable({ accountId: null })
useEffect(async () => {
const userData = fetch(`/user/${user.accountId}`)
user.profile = userData.profile
})
```
* effects trigger if observable updates

</div>

</div>
67 changes: 17 additions & 50 deletions docs/guides/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,59 +33,26 @@ Tram-One is a light View Framework that comes with all the dependencies you need

Tram-One is an orchestration of common features, and relies only on plain pure javascript, so you don't have to bother learning / parsing / transpiling special templating languages. It relies only on ES6 Template Strings, which are [supported in most major browsers](https://caniuse.com/#feat=template-literals).

```javascript
import { registerHtml, start } from 'tram-one'
const html = registerHtml()
<iframe
src="https://stackblitz.com/edit/tram-one-docs-introduction-example-one?embed=1&file=index.js&hideExplorer=1"
width="100%"
height="350px"
></iframe>
const home = () => {
return html`
<div>
<h1>Tram One</h1>
<h2>A Modern View Framework</h2>
</div>
`
}
Tram-One takes inspiration from frameworks like [Choo](https://choo.io/), [React](https://reactjs.org/), and [Svelte](https://svelte.dev/). Tram-One includes a set of default hooks, similar to React and Svelte, which allow for
routing, effects, component state, and global state management.

start('#app', home)
```

Tram-One takes inspiration from frameworks like [Choo](https://choo.io/) and [React](https://reactjs.org/). Tram-One includes a set of default hooks, similar to React, which allow for
routing, component state, and global state management.

```javascript
import { registerHtml, useState } from 'tram-one'
const html = registerHtml()

export default () => {
const [count, updateCount] = useState(0)
const incrementCount = () => updateCount(count + 1)
return html`
<button
class="counter-button"
onclick=${incrementCount}
>
${count}
</button>
`
}
```
<iframe
src="https://stackblitz.com/edit/tram-one-docs-introduction-example-two?embed=1&file=index.js&hideExplorer=1"
width="100%"
height="350px"
></iframe>
The syntax is based on similar modules that Choo uses, offering custom components in a
js template syntax that should be familiar and confortable to React developers.

```javascript
import { registerHtml, useState } from 'tram-one'
import Counter from './Counter'
const html = registerHtml({
'Counter': Counter,
})

export default () => {
return html`
<div>
<span>Click the button below to update your count</span>
<Counter />
</div>
`
}
```
<iframe
src="https://stackblitz.com/edit/tram-one-docs-introduction-example-three?embed=1&file=index.js&hideExplorer=1"
width="100%"
height="350px"
></iframe>
4 changes: 0 additions & 4 deletions docs/guides/tram-one-express.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,3 @@ npm start

You will see a web application with a title bar, and some simple text. Feel free
from here to play around, build new components, and remove existing ones.


If you want to learn more of the features in a step by step guide, go to our
[tutorial](/tutorial) to learn all the features available in Tram-One!
Loading

0 comments on commit 84c1ee3

Please sign in to comment.