A tiny foundation for building reactive views

Related tags

Frameworks ripple
Overview

ripple.js

Build Status

A tiny foundation for building reactive views with plugins. It aims to have a similar API to Reactive, but allow composition of views, like React. The major difference for other view libraries is that there are no globals used at all. Each view has its own set of bindings and plugins. This makes composition of views really easy.

var Person = ripple('<div>{{name}}</div>')
  .attr('name', { required: true, type: 'string' });

var person = new Person({
  name: 'Tom'
});

person.appendTo(document.body);
person.name = "Barry"; // DOM updates automatically

Install

component install ripplejs/ripple

Browser Support

Supports real browsers and IE9+.

Documentation

Documentation is on the wiki.

Examples

See more examples at ripplejs/examples

Plugins

  • shortcuts - add custom key binding combos
  • events - add event listeners to the DOM and call methods on the view
  • each - Basic iteration using the each directive.
  • bind-methods - Bind all methods on the prototype to the view
  • markdown - Adds a directive to render markdown using Marked.
  • extend - Makes adding methods to the view prototype a little cleaner
  • intervals - Easily add and remove intervals
  • computed - Add computed properties.
  • refs - Easily reference elements within the template
  • dispatch - Dispatch custom DOM events up the tree

View and add them on the wiki

License

MIT

Comments
  • Firing events/methods when data changes

    Firing events/methods when data changes

    Following Anthony's suggestion, im posting this question here since there isn't yet a StackOverflow or forum where this kind of request probably fit better. Hope you don't mind and can point some directions to where look further.

    Im trying to build a small component, based on the iteration example, where I have a list of numbers that I can add or remove items.

    I've published the working sample here: http://jsfiddle.net/lmartins/VPB93/

    Let's say I wanted to achieve the following:

    • When no items on the list show a "no items" message instead - This would happen of first page load and if the user deleted all items

    What would you suggest doing to achieve this, I though of custom events or setting an watcher on the items array using the observer plugin but im still lacking the knowledge to figure how all the parts fit together.

    opened by lmartins 14
  • content insertion

    content insertion

    Is it possible to insert content into composed components like this?

    <app-sidebar>
      <li>home</li>
      <li>profile</li>
    </app-sidebar>
    

    app-sidebar:

    <div>
      <ul>
        <!-- content from component goes here -->
        <content></content>
      </ul>
    <div>
    

    This is how it's done with native web components. Is there a ripple way? Couldn't find anything in the documentation.

    opened by queckezz 6
  • Emit an event when a view is created

    Emit an event when a view is created

    I'm not sure if this is the correct way to do it but I didn't found another solution. This basically allows manipulating the view object when a new Ripple instance is created:

    Ripple.on('construct', function (View) {
    })
    

    Maybe construct is not the best name and I should have called it instance or something. This would also allow ripple-router#34 to work.

    What do you think?

    opened by queckezz 6
  • how does data flow to children?

    how does data flow to children?

    Starting to play with ripple and reading the composition docs. It says that the parents pass the data to the children. I'm a bit confused on what you give the parents to render the children correctly. Is it an array of objects? Example:

    [
      {
        username: "anthony",
        ...
      },
      {
        username: "matt",
        ...
      }
    ]
    
    opened by matthewmueller 5
  • Example setup without using Component

    Example setup without using Component

    It would be rather useful to see a working example without using component. I am considering using ripple in my current project- which uses requirejs to manage modules. Else, if I get some guidance I could eventually do this myself and submit a PR.

    opened by goliatone 4
  • Each iterator on the repeated DOM element instead of container

    Each iterator on the repeated DOM element instead of container

    Following the iteration example, i've noticed that the directive is passed in the container element instead of the element being cloned at each loop.

    This might present some limitations, one example being the following. Let's say I have a ul that contains my data items. When there are no items to show I wan't to show an li with some specific formatting. If I try that now, just by having the extra liinside the element where each is applied it breaks.

    This is more a question than a suggestion, just curious about the reasons behind that design option.

    opened by lmartins 4
  • Trying to build the examples

    Trying to build the examples

    The directions say "In each directory run make build, then open up index.html." When I cd into a directory and type make build, I get the error make: *** No rule to make target `build'. Stop.

    Can anyone help me get this started?

    Make build at the top level does work, and seems to install a shit-ton of things, so the tool is actually working...

    opened by walterdavis 4
  • Reactive arrays

    Reactive arrays

    I have a property set to an array and I want to be able to get its length attribute on the template. Is that possible using ripplejs/ripple standalone or using any plugin?

    My code looks like the following:

    var ripple = require('ripple');
    var template = '<div>{{items.length}}</div>';
    var View = ripple(template);
    
    View.attr('items', {type: 'array'});
    
    View.on('ready', function(view) {
      setTimeout(function () {
        view.get('items').push(1); // does not update the template
      }, 1000);
    });
    
    var view = new View({items: [10, 20, 30, 0, 4]});
    
    view.appendTo(document.body);
    
    opened by sachalifs 3
  • Event handlers to Views created with selectors

    Event handlers to Views created with selectors

    1. Creating view with selector

    When I run the test suite the following test is running well:

      it('should create a view with a selector', function () {
        var test = document.createElement('div');
        test.id = 'foo';
        document.body.appendChild(test);
        View = ripple('#foo');
        var view = new View();
        assert(view.template = '<div id="foo"></div>');
      });
    

    But in reality when I try to create a view with selector out of existing DOM it cuts out the wrapper. For example:

    html -> <button id='myButton'>Save</button>

    js -> var View = ripple('#myButton'); var viewInstance = new View()

    I end up having viewInstance.template = 'Save'. I guess due to this code in getTemplate:

      if (typeof template.innerHTML === 'string') {
        template = template.innerHTML;
      }
    

    2. View with selector + Event Handlers (events plugin)

    What is the best practice of attaching event handlers to Views created with selectors?

    Again:

    html -> <button id='myButton' on-click="{{ this.save }}">Save</button>

    js -> var View = ripple('#myButton'); ....

    I found that I must do viewInstance.replace('#myButton') (probably to trigger mount event and make it work). And note that this is only going to work if I avoid the problem in 1. I put myButton in kind of wrapper - lets say:

    <div id='d'><button id='myButton' on-click="{{ this.save }}">Save</button></div>

    and then var View = ripple('#d');

    opened by pltod 3
  • Template Spec (or Documentation) is Unclear...

    Template Spec (or Documentation) is Unclear...

    It seems that templates only work if they are composed of a single DOM element, even if it's a simple

    ...

    This is not obvious in the documentation -- and templates without this minor wrapper element seem not to parse correctly beyond the first element.

    It may be this is by design, but, if so - it's not obvious without inspecting all the examples, etc. :)

    (no examples provided, but take any of the standard examples, and remove the outer wrapper element... :-1: )

    -Dx

    opened by Xalior 3
  • Uncaught TypeError on data array event attachment

    Uncaught TypeError on data array event attachment

    When trying to attach the change event to a data array, I get the following error: Uncaught TypeError: undefined is not a function

    You can see the problem in jsfiddle: http://jsfiddle.net/lmartins/VPB93/

    opened by lmartins 3
  • doc correction

    doc correction

    https://github.com/ripplejs/ripple/wiki/Composing-Views:

     var Avatar = ripple('<img src="http://graph.facebook.com/{{username}}/profile" />');
    

    should be changed to:

    var Avatar = ripple('<img src="http://graph.facebook.com/{{username}}/picture" />');
    
    opened by rickdog 0
  • 'template' definition needed

    'template' definition needed

    The wiki documentation would be easier to grasp if you included a definition of or reference to 'template' in https://github.com/ripplejs/ripple/wiki/Interpolation. It's not until near the doc end where 'template' is defined in https://github.com/ripplejs/ripple/wiki/Composing-Views.

    opened by rickdog 0
  • Add docs badge to README

    Add docs badge to README

    Hi there,

    I want to propose to add this badge to the README to show off inline-documentation: Inline docs

    The badge links to Inch CI and shows an evaluation by InchJS, a project that tries to raise the visibility of inline-docs. Besides testing and other coverage, documenting your code is often neglected although it is a very engaging part of Open Source that encourages aspiring developers to jump into the source and see how it all ties together.

    So far over 600 Ruby projects are sporting these badges to raise awareness for the importance of inline-docs and to show potential contributors that they can expect a certain level of code documentation when they dive into your project's code and motivate them to eventually document their own. I would really like to do the same for the JavaScript community and roll out support for JS over the coming weeks (early adopters are forever, node-sass and when).

    Although this is "only" a passion project, I really would like to hear your thoughts, critique and suggestions. Your status page is http://inch-ci.org/github/ripplejs/ripple

    What do you think?

    opened by rrrene 0
  • CustomEvent is not newable in IE11

    CustomEvent is not newable in IE11

    Hi, ripples.js is very good! However an error has occurred in IE11.

    the error in line 48

    rippleEnd           = new CustomEvent("rippleEnd", {detail: $ripple}),
    

    IE11's CustomEvent is not able to new. I add some code and use in my project. It is following code and exec in if browser's CustomEvent is not newable.

    rippleEnd = document.createEvent("CustomEvent");
    rippleEnd.initCustomEvent("rippleEnd", false, false, { detail: $ripple });
    

    for your information.

    I thank you for reading my funny english through.

    opened by iwate 0
  • How to compose views one inside of the other?

    How to compose views one inside of the other?

    After readed the examples https://github.com/ripplejs/ripple/wiki/Composing-Views I like to know if is possible compose one view, inside of the other.

    I have something like this:

     <div class="social-networks">
        <a href="http://twitter.com/">Twitter</a>
        <a href="http://facebook.com/">Facebook</a>  
    </div>
    

    and I would like to add inside of the oter views, in diferent points like:

     <div class="user-profile-networks">
        <p>{{name}}</p>
        <p>{{lastName}}</p>
        <p>{{email}}</p>
      <!-- social network view here-->
     <br> 
     <p>{{adress}}</p>  
    </div>
    

    Is this possible?

    opened by vmariano 0
  • 0.6.0 API changes

    0.6.0 API changes

    As part of the changes I'm making to the API for 0.6, I thought I'd talk about some of the goals and things I want to fix:

    Extract the data-binding engine

    This will allow me to finish of the virtual DOM engine. When creating a view you would need to choose a rendering engine for the view.

    var bindings = binder(template)
      .use(someDirective)
      .use(someFiltersAndShit);
    
    var View = ripple()
      .engine(bindings);
    

    The syntax for this is still a little in progress, but the code behind it works, it's just a matter of making it feel nice in the API.

    Less confusing API

    At the moment, you need to listen to events on the class and possibly on the instance.

    View.on('mounted', function(view){
      view.foo = bar;
    });
    
    View.prototype.submit = function() {
      this.foo = bar;
    };
    

    This is a little confusing having them next to each other but with a different syntax. Obviously one is an event and the other is a handler. There are a couple of examples of how this could work here: https://gist.github.com/anthonyshort/2dbf56c398f320a4db61

    Option 1:

    At the moment, I think this might be the nicest solution:

    var View = ripple({
      initialize: function(){},
      mounted: function(){
        this.foo = bar;
      }, 
      submit: function(){
        this.foo = bar;
      }
    });
    
    View
      .use(binding(template))
      .attr('foo');
    

    And if a key an event lifecycle name we'd add it as a callback automatically. This is a little too much magic possibly, but it does create a nice abstraction and allows all the methods to be in place.

    Option 2

    We use the ripple() function to create View that we inherit from:

    var View = ripple()
      .engine(bindings)
      .attr('firstName')
      .attr('lastName');
    
    View.on('initialize', function(view){
      view.foo = bar;
    });
    
    module.exports = View.extend({
      onClick: function(event){
        console.log('clicked!'); 
      }
    });
    

    Again, I think this confuses things because there are two different ways to add 'methods' and each has a different context. We'd also be using inheritance.

    Option 3

    Using a handler or method function to add methods so that it follows the same syntax as the events:

    View.on('initialize', function(view){
      view.foo = bar;
    });
    
    View.handler('onClick', function(view, event){
      view.foo = bar;
    });
    

    Allow for ES6 modules and classes

    If we used Option 1 above, it could possibly allow us to have a nice syntax for using ES6 classes. It's not necessary, but it would be nice.

    import ripple from 'ripple';
    import binder from 'binder';
    import template from './template';
    
    var bindings = binder()
      .use(someDirective)
      .use(someFiltersAndShit);
    
    class View {
      constructor() {
        super();
        console.log('initializing a view!');
      },
      onClick(event) {
        console.log('clicked!');
      }
    }
    
    export ripple(View)
      .engine(bindings(template))
      .attr('firstName')
      .attr('lastName');
    

    With an alternative syntax using extends

    var Base = ripple()
      .engine(bindings(template))
      .attr('firstName')
      .attr('lastName');
    
    exports class View extends Base {
      initialize() {
        console.log('initializing a view!');
      },
      onClick(event) {
        console.log('clicked!');
      }
    }
    

    Option 1, at the very least, would allow us to do this:

    var View = ripple({
      mounted() {
        this.foo = bar;
      }, 
      submit() {
        this.foo = bar;
      }
    });
    
    opened by anthonyshort 16
Owner
ripple.js
Modular components for reactive views
ripple.js
Give your JS App some Backbone with Models, Views, Collections, and Events

____ __ __ /\ _`\ /\ \ /\ \ __ \ \ \ \ \ __ ___\ \ \/'\\ \ \_

Jeremy Ashkenas 28k Dec 27, 2022
The tiny framework for building hypertext applications.

Hyperapp The tiny framework for building hypertext applications. Do more with less—We have minimized the concepts you need to learn to get stuff done.

Jorge Bucaran 18.9k Jan 4, 2023
🙋‍♀️ 3kb library for tiny web apps

3kb library for tiny web apps. Sometimes, all you want to do is to try and do something—No boilerplate, bundlers, or complex build processes. Lucia ai

Aiden Bai 699 Dec 27, 2022
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

Supporting Vue.js Vue.js is an MIT-licensed open source project with its ongoing development made possible entirely by the support of these awesome ba

vuejs 201.7k Jan 8, 2023
Lightweight MVC library for building JavaScript applications

Spine Spine is a lightweight MVC library for building JavaScript web applications. Spine gives you structure and then gets out of your way, allowing y

Spine JS Project 3.6k Jan 4, 2023
A framework for building native apps with React.

React Native Learn once, write anywhere: Build mobile apps with React. Getting Started · Learn the Basics · Showcase · Contribute · Community · Suppor

Facebook 106.8k Jan 3, 2023
A JavaScript Framework for Building Brilliant Applications

mithril.js What is Mithril? Installation Documentation Getting Help Contributing What is Mithril? A modern client-side JavaScript framework for buildi

null 13.5k Dec 26, 2022
:fire: An extremely fast, React-like JavaScript library for building modern user interfaces

Inferno is an insanely fast, React-like library for building high-performance user interfaces on both the client and server. Description The main obje

Inferno 15.6k Jan 3, 2023
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A tiny foundation that providing nested state-based routing for complex web application.

StateMan stateman: A tiny foundation that provides nested state-based routing for complex web applications. stateman is highly inspired by ui-router;

ZhengHaibo 390 Dec 20, 2022
A tiny, reactive JavaScript library for structured state and tabular data.

A JavaScript library for structured state. Using plain old JavaScript objects to manage data gets old very quickly. It's error-prone, tricky to track

tinyplex 1.4k Jan 1, 2023
Marble.js - functional reactive Node.js framework for building server-side applications, based on TypeScript and RxJS.

Functional reactive Node.js framework for building server-side applications, based on TypeScript and RxJS. Ecosystem Name Description @marblejs/core F

Marble.js 2.1k Dec 16, 2022
Estrela - a JavaScript library for building reactive web components inspired by lit

Estrela ⭐ Full Reactive Web Components Estrela is a JavaScript library for building reactive web components inspired by lit. Just like Lit, Estrela is

null 50 Oct 31, 2022
Give your JS App some Backbone with Models, Views, Collections, and Events

____ __ __ /\ _`\ /\ \ /\ \ __ \ \ \ \ \ __ ___\ \ \/'\\ \ \_

Jeremy Ashkenas 28k Jan 9, 2023
Lightweight analytics abstraction layer for tracking page views, custom events, & identifying visitors

A lightweight analytics abstraction library for tracking page views, custom events, & identify visitors. Designed to work with any third-party analyti

David Wells 1.9k Dec 31, 2022
Give your JS App some Backbone with Models, Views, Collections, and Events

____ __ __ /\ _`\ /\ \ /\ \ __ \ \ \ \ \ __ ___\ \ \/'\\ \ \_

Jeremy Ashkenas 28k Dec 27, 2022
Single Page Application micro framework. Views, routes and controllers in 60 lines of code

SPApp Single Page Application Micro Framework Supports views, controllers and routing in 60 lines of code! Introduction If you heard anything about MV

Andrew 262 Nov 23, 2022