How to use the cyclejs.createModel function in cyclejs

To help you get started, we’ve selected a few cyclejs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ivan-kleshnin / cyclejs-examples / examples / 1.2-timer-more / dist / scripts / app.js View on Github external
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o
github ivan-kleshnin / cyclejs-examples / static / 1.1-timer / scripts / app.js View on Github external
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o
github ivan-kleshnin / cyclejs-examples / frontend / 1.1-timer / scripts / app.js View on Github external
// IMPORTS =========================================================================================
require("../../common/scripts/shims");
let Cycle = require("cyclejs");
let {Rx, h} = Cycle;

// APP =============================================================================================
let Model = Cycle.createModel(() => {
  let started = Date.now();
  return {
    msSinceStart$: Rx.Observable.interval(100)
      .map(() => Date.now() - started)
  };
});

let View = Cycle.createView(Model => {
  return {
    vtree$: Model.get("msSinceStart$").map(msSinceStart => {
      let timeDelta = (msSinceStart / 1000).toFixed(1);
      return (
        <div>
          Started {timeDelta} seconds ago
        </div>
      );
github ivan-kleshnin / cyclejs-examples / frontend / 4.1-menu-basic / scripts / menu.js View on Github external
Cycle.registerCustomElement("Menu", (User, Props) =&gt; {
  let Model = Cycle.createModel((Intent, Props) =&gt; {
    return {
      items$: Props.get("items$").startWith([]),
      active$: Props.get("active$")
        .merge(Intent.get("selectActive$"))
        .startWith([]),
    }
  });

  let View = Cycle.createView(Model =&gt; {
    let items$ = Model.get("items$");
    let active$ = Model.get("active$");
    return {
      vtree$: items$.combineLatest(active$, (items, active) =&gt; {
        return (
          <div>
            <nav></nav></div>
github ivan-kleshnin / cyclejs-examples / src / 3.2-slider-state / scripts / slider.js View on Github external
Cycle.registerCustomElement("Slider", (DOM, Props) =&gt; {
  let Model = Cycle.createModel((Intent, Props) =&gt; ({
    id$: Props.get("id$"),
    width$: Props.get("width$").merge(Intent.get("changeWidth$")),
  }));

  let View = Cycle.createView(Model =&gt; {
    let id$ = Model.get("id$");
    let width$ = Model.get("width$");
    return {
      vtree$: width$.combineLatest(id$, (width, id) =&gt; (
        <div width="" style="{{width:" class="item">
          <div>
            <input value="{width}/" max="1000" min="200" type="range" class="width-slider">
          </div>
        </div>
      )),
    };
github ivan-kleshnin / cyclejs-examples / src / 3.1-slider-intro / scripts / item.js View on Github external
let width$ = Model.get("width$");
    return {
      vtree$: Rx.Observable.combineLatest(width$, (width) =&gt; {
          return (
            <div width="" style="{{width:" class="item">
              <div>
                <input value="{width}/" max="1000" min="200" type="range" class="width-slider">
              </div>
            </div>
          );
        }
      ),
    };
  });

  let Model = Cycle.createModel((Intent, Props) =&gt; {
    return {
      width$: Props.get("width$"),
    };
  });

  let Intent = Cycle.createIntent(DOM =&gt; {
    return {
      changeWidth$: DOM.event$(".width-slider", "input").map(event =&gt; parseInt(event.target.value))
    };
  });

  DOM.inject(View).inject(Model).inject(Intent, Props)[0].inject(DOM);

  return {
    changeWidth$: Intent.get("changeWidth$"),
  };
github ivan-kleshnin / cyclejs-examples / frontend / 3.2-slider-state / scripts / slider.js View on Github external
Cycle.registerCustomElement("Slider", (User, Props) =&gt; {
  let Model = Cycle.createModel((Intent, Props) =&gt; ({
    id$: Props.get("id$"),
    value$: Props.get("value$")
      .merge(Intent.get("changeValue$"))
      .startWith(0),
  }));

  let View = Cycle.createView(Model =&gt; {
    let id$ = Model.get("id$");
    let value$ = Model.get("value$");
    return {
      vtree$: value$.combineLatest(id$, (value, id) =&gt; (
        <div class="form-group">
          <label>Amount</label>
          <div class="input-group">
            <input placeholder="Amount" value="{value}" type="range">
            <div class="input-group-addon"></div></div></div>
github ivan-kleshnin / cyclejs-examples / src / 3.2-slider-state / scripts / item.js View on Github external
let width$ = Model.get("width$");
    return {
      vtree$: Rx.Observable.combineLatest(id$, width$, (id, width) =&gt; {
          return (
            <div width="" style="{{width:" class="item">
              <div>
                <input value="{width}/" max="1000" min="200" type="range" class="width-slider">
              </div>
            </div>
          );
        }
      ),
    };
  });

  let Model = Cycle.createModel((Intent, Props) =&gt; {
    return {
      id$: Props.get("id$").shareReplay(1),
      width$: Props.get("width$"),
    };
  });

  let Intent = Cycle.createIntent(DOM =&gt; {
    return {
      changeWidth$: DOM.event$(".width-slider", "input").map(event =&gt; parseInt(event.target.value)),
    };
  });

  DOM.inject(View).inject(Model).inject(Intent, Props)[0].inject(DOM);

  return {
    changeWidth$: Intent.get("changeWidth$")
github ivan-kleshnin / cyclejs-examples / frontend / 3.4-slider-colors / scripts / slider.js View on Github external
Cycle.registerCustomElement("Slider", (User, Props) => {
  let Model = Cycle.createModel((Intent, Props) => ({
    id$: Props.get("id$").shareReplay(1),

    value$: Props.get("value$")
      .merge(Intent.get("changeValue$"))
      .startWith(0),

    color$: Props.get("color$")
      .merge(Intent.get("changeColor$"))
      .startWith("#F00"),
  }));

  let View = Cycle.createView(Model => {
    let id$ = Model.get("id$");
    let value$ = Model.get("value$");
    let color$ = Model.get("color$");
    return {
github ivan-kleshnin / cyclejs-examples / static / 3.1-slider-intro / scripts / app.js View on Github external
Cycle.registerCustomElement("Slider", function (User, Props) {
  var Model = Cycle.createModel(function (Intent, Props) {
    return {
      value$: Props.get("value$").merge(Intent.get("changeValue$")).startWith(0) };
  });

  var View = Cycle.createView(function (Model) {
    var value$ = Model.get("value$");
    return {
      vtree$: value$.map(function (value) {
        return h("div", { className: "form-group" }, [h("label", null, ["Amount"]), h("div", { className: "input-group" }, [h("input", { type: "range", value: value, placeholder: "Amount" }), h("div", { className: "input-group-addon" }, [h("input", { type: "text", value: value, readonly: "1" })])])]);
      }) };
  });

  var Intent = Cycle.createIntent(function (User) {
    return {
      changeValue$: User.event$("[type=range]", "input").map(function (event) {
        return parseInt(event.target.value);