How to use the cyclejs.createView 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 / static / 2.2-hello-footer / scripts / app.js View on Github external
},{"cyclejs":"cyclejs"}],5:[function(require,module,exports){
"use strict";

// IMPORTS =========================================================================================
var Cycle = require("cyclejs");
var Rx = Cycle.Rx;
var h = Cycle.h;

var Footer = require("./footer");

// EXPORTS =========================================================================================
var View = Cycle.createView(function (Model) {
  var firstName$ = Model.get("firstName$");
  var lastName$ = Model.get("lastName$");
  return {
    vtree$: Rx.Observable.combineLatest(firstName$, lastName$, function (firstName, lastName) {
      return h("div", null, [h("div", { className: "form-group" }, [h("label", null, ["First Name:"]), h("input", { type: "text", className: "form-control", id: "firstName", placeholder: "First Name" })]), h("div", { className: "form-group" }, [h("label", null, ["Last Name:"]), h("input", { type: "text", className: "form-control", id: "lastName", placeholder: "Last Name" })]), h("h1", null, ["Hello ", firstName + " " + lastName, "!"]), h("Footer", { className: "xxx" }, ["content"])]);
    }) };
});

module.exports = View;

},{"./footer":2,"cyclejs":"cyclejs"}],6:[function(require,module,exports){
"use strict";
github ivan-kleshnin / cyclejs-examples / src / 4.1-menu-basic / scripts / app.js View on Github external
// IMPORTS =========================================================================================
let Cycle = require("cyclejs");
let {Rx, h} = Cycle;
let Menu = require("./menu");

// APP =============================================================================================
let data = [
  "Home", "Services", "About", "Contact us"
];

let active = "Services";

let View = Cycle.createView(() => ({
  vtree$: Rx.Observable.return(
    <menu>
  ),
}));

Cycle.createDOMUser("main").inject(View);</menu>
github ivan-kleshnin / cyclejs-examples / static / 4.2-menu-form / scripts / app.js View on Github external
"use strict";

// IMPORTS =========================================================================================
require("../../common/scripts/shims");
var Cycle = require("cyclejs");
var Rx = Cycle.Rx;
var h = Cycle.h;

var Menu = require("./menu");

// APP =============================================================================================
var data = [{ name: "Web Development", price: 300 }, { name: "Design", price: 400 }, { name: "Integration", price: 250 }, { name: "Training", price: 220 }];

var active = ["Web Development", "Integration"];

var View = Cycle.createView(function () {
  return {
    vtree$: Rx.Observable["return"](h("div", null, [h("Menu", { items: data, active: active })])) };
});

Cycle.createDOMUser("main").inject(View);

},{"../../common/scripts/shims":3,"./menu":2,"cyclejs":"cyclejs"}],2:[function(require,module,exports){
"use strict";
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(() =&gt; {
  let started = Date.now();
  return {
    msSinceStart$: Rx.Observable.interval(100)
      .map(() =&gt; Date.now() - started)
  };
});

let View = Cycle.createView(Model =&gt; {
  return {
    vtree$: Model.get("msSinceStart$").map(msSinceStart =&gt; {
      let timeDelta = (msSinceStart / 1000).toFixed(1);
      return (
        <div>
          Started {timeDelta} seconds ago
        </div>
      );
    }),
  };
});

let User = Cycle.createDOMUser("main");

User.inject(View).inject(Model);
github ivan-kleshnin / cyclejs-examples / frontend / 3.1-slider-intro / scripts / view.js View on Github external
// IMPORTS =========================================================================================
let Cycle = require("cyclejs");
let {Rx, h} = Cycle;
let Slider = require("./slider");

// EXPORTS =========================================================================================
let View = Cycle.createView(Model =&gt; {
  let value$ = Model.get("value$");
  return {
    vtree$: value$.map(value =&gt; (
      <div class="everything">
        <div>
          
        </div>
      </div>
    )),
  };
});

module.exports = View;
github ivan-kleshnin / cyclejs-examples / src / 3.3-slider-multiple / scripts / slider.js View on Github external
Cycle.registerCustomElement("Slider", (DOM, Props) =&gt; {
  let Model = Cycle.createModel((Intent, Props) =&gt; ({
    id$: Props.get("id$").shareReplay(1),
    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>
          <button class="remove">Remove</button>
        </div>
      )),
    };
  });

  let Intent = Cycle.createIntent(DOM =&gt; {
    return {
github ivan-kleshnin / cyclejs-examples / src / 3.4-slider-colors / scripts / slider.js View on Github external
Cycle.registerCustomElement("Slider", (DOM, Props) =&gt; {
  let Model = Cycle.createModel((Intent, Props) =&gt; ({
    id$: Props.get("id$").shareReplay(1),
    width$: Props.get("width$").merge(Intent.get("changeWidth$")),
    color$: Props.get("color$").merge(Intent.get("changeColor$")),
  }));

  let View = Cycle.createView(Model =&gt; {
    let id$ = Model.get("id$");
    let width$ = Model.get("width$");
    let color$ = Model.get("color$");
    return {
      vtree$: id$.combineLatest(width$, color$, (id, width, color) =&gt; (
        <div width="" style="{{width:" class="item">
          <div>
            <input value="{width}/" max="1000" min="200" type="range" class="width-slider">
          </div>
          <div>
            <input value="{color}/" type="text" class="color-input">
          </div>
          <button class="remove">Remove</button>
        </div>
      )),
    };
github ivan-kleshnin / cyclejs-examples / src / 4.1-menu-basic / scripts / menu.js View on Github external
Cycle.registerCustomElement("Menu", (DOM, Props) =&gt; {
  let Model = Cycle.createModel((Intent, Props) =&gt; {
    let items$ = Props.get("items$");
    let active$ = Props.get("active$");
    let selectActive$ = Intent.get("selectActive$");
    return {
      items$: items$,
      active$: active$.merge(selectActive$),
    }
  });

  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>
              {items.map(item =&gt;
                <div class="{makeClass({&quot;item&quot;:">
                  {item}
                </div>
              )}
            </nav>
            <p>
              Selected: <b>{active}</b></p></div>
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">
              <input readonly="1" value="{value}" type="text">
            </div>
          </div>
        </div>
      )),
    };
  });
github ivan-kleshnin / cyclejs-examples / static / 4.3-menu-fun / scripts / app.js View on Github external
});
  var randomCount = randomInt(names.length - 1);
  var randomItems = range(randomCount).map(function () {
    return randomFrom(names);
  });
  return Array.from(new Set(randomItems));
}

var Model = Cycle.createModel(function () {
  return {
    active$: Rx.Observable.interval(2000).map(function () {
      return generateRandomActive(data);
    }) };
});

var View = Cycle.createView(function (Model) {
  return {
    vtree$: Model.get("active$").map(function (active) {
      return h("div", null, [h("Menu", { items: data, active: active })]);
    }) };
});

Cycle.createDOMUser("main").inject(View).inject(Model);

},{"../../common/scripts/shims":3,"./menu":2,"cyclejs":"cyclejs","lodash.range":4}],2:[function(require,module,exports){
"use strict";