asyncanup's notebooks

  • React + ReactDOM in a tweet - /asyncanup/react-in-a-tweet
    Last edited 17 hours ago
    // paste into react.jsbin.com // remove scripts loading the actual react lib if any // https://react.jsbin.com/godotur/1/edit?js,output // React + ReactDOM.render (no virtual DOM) function Co(p){this.props=p}A='appendChild',g=a=>a.map?a.flatMap(g):[a] React={[C='createElement']:(t,p,...c)=>t.bind?new t(p):(e=document[C](t),(()=>{for(n in p)e[n]=p[n]})(),g(c).map(a=>e[A](a.tagName?a:new Text(a))),e)} render=(r,h)=>(r.h=h,h[A](r.render())) // the correct one // function Co(p){this.props=p}A='appendChild',g=a=>(a||'').map?a.flatMap(g):[a||''] // React={[C='createElement']:(t,p,...c)=>t.bind?new t(p):(e=document[C](t),(()=>{for(n in p)e[n]=p[n]})(),g(c).map(a=>e[A](a.tagName?a:new Text(a))),e)} // render=(r,h)=>(r.h=h,h[A](r.render())) // Additional plugin, if you also want setState Co.prototype.setState=function(s){ this.state={...this.state,...s} this.h.innerHTML='' render(this,this.h) } // Usage class App extends Co { constructor(){super();this.state={count:0}} handleClick() {this.setState({count:this.state.count+1})} render() { return (<div onclick={this.handleClick.bind(this)} style="color:green;font-weight:bold;">Count: {this.state.count}</div>); } } render( <App/>, document.getElementById('container') );
  • slackbot-is-president-__ - /asyncanup/slackbot-is-the-president
    Last edited 2 years ago
    require('@runkit/runkit/express-endpoint/1.0.0')(exports) .post('/', require('body-parser')(), (req, res) => { res.json({ text: `_${req.body.text}_?\n*${Math.ceil(Math.random()*100)}% sure ${Math.random()>0.5?'YES':'NO'}!*`, response_type: 'in_channel' }) })
  • falcor-dummy-server - /asyncanup/falcor-dummy-server
    Last edited 3 years ago
    var falcor = require('falcor'); var FalcorServer = require('falcor-express'); var bodyParser = require('body-parser'); var express = require("@runkit/runkit/express-endpoint/1.0.0"); var app = express(exports); var model = new falcor.Model({ cache: { todos: [ { name: 'get milk from corner store', done: false }, { name: 'withdraw money from ATM', done: true } ] } }); app.use(bodyParser.text({ type: 'text/*' })) app.use('/model.json', FalcorServer.dataSourceRoute(function(req, res) { return model.asDataSource(); })); app.get('/', (req, res) => res.send('hi')); console.log('started');