2.3.0 • Published 5 years ago

anticore-serverless v2.3.0

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

anticore-serverless

An utility to easily write and test your anticore's middlewares, serverless

Install

`npm i anticore-serverless

Live demo

anticore-serverless demo

Usage

Listen a form submit

Supposing you have a middleware to add some new messages to a messages list, like this:

import { anticore } from 'anticore'
import { one } from 'anticore/dom/query/one'
import { append } from 'anticore/dom/tree/append'

anticore.on('#messages li', (message, next) => {
  append(message, one('#messages'))
  next()
})

Register your templater like this:

import serverless from 'anticore-serverless'

serverless.on('main#message-sender form', (url, data, escape, session) => {
  return `<ol id="messages">
    <li>${escape(data.message)}</li>
  </ol>`
})

Listen an anchor click

Supposing you have a middleware to load a new view, like this:

import { anticore } from 'anticore'
import { onClick } from 'anticore/dom/emitter/on/onClick'
import { one } from 'anticore/dom/query/one'
import { replace } from 'anticore/dom/tree/replace'


anticore.on('section.hello', (section, next) => {
  const main = one('main')

  replace(section, main)
  onClick(one('.closer', section), () => replace(main, section))

  next()
})

Register your templater like this:

import serverless from 'anticore-serverless'

serverless.on('a[href="/say-hello"]', (url, escape, session) => {
  return `<section class="hello">
    <h1>Hello world</h1>
    <p>You asked the following url : ${escape(url)}</p>
    <button class="closer">Close</button>
  </section>`
})

API

/**
* Listens a form/anchor selector and sends the response to anticore, based
* on the templater result
* @param {string} selector
* @param {function} templater
* @return {this}
*/
import serverless from 'anticore-serverless'

serverless.on(selector, templater)

Session

session = session.set(name, value)
value = session.get(name)
session = session.reset()

License

MIT

2.3.0

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago