Super minimal MVC library

Overview

Espresso.js

Espresso.js is a tiny MVC library inspired by Backbone and React with a focus on simplicity and speed.

We've aimed to bring the ideas of unidirectional data flow of Flux to a simple, Backbone-style library.

Features

  • tiny, less than 500 lines and 3kb gzipped
  • zero dependencies
  • performance and memory focused
  • does not aim to support anything below IE10, but may work on older browsers using a shim

Documentation

Backbone-style docs can be found here

All documentation is automatically generated from docs/index.md using Bocco.

Getting Started

If you're using Browserify or Node/CommonJS, simply install the package:

$ sudo npm install --save espresso.js

Alternatively grab the standalone version that you can import with a <script> tag or checkout the GitHub Repo.

Now dive in and check out the To-Do Example app.

Testing

$ npm test

Building

If you need to use this module outside a CommonJS environment, you can build a standalone UMD module as follows:

$ npm run build
Comments
  • Possible bug or I'm confused.

    Possible bug or I'm confused.

    Edit: NVM, you can close this....

    it turns out it was my fault; if you use syntax for (i in arr){ collection.push({id: i, ...}) console.log(i, typeof i) } you'll see JS uses a string type for index, and that breaks the collections update/find Fn's

    sorry.....

    Hi I'm a little confused on Collection.set and Collection.push, can you tell me if this is a bug?

    Anyway If you use collection.push({id: 9999, otherfield: 1234}) collection.set({id: anyid, ...}) no longer works... I assume this is because either you cannot set the ID from push, you cannot start above 0, or you cant use abritrary IDs from the backend ^_^.

    1. What is the correct way to add an item to collection, .push()? Is it without specifying an id?
    • I am using push({ id: 9999, otherfield: 1234, otherfield2: 1234 }), and i'm using Ids > 0 as my first item, I think this is causing the problem
    1. What is the correct way to update one field of one item to that collection?
    • If I do collection.set({ id: 1, field2: 'newdata'}), sometimes the entire object is replaced with this new smaller object (now only has these 2 fields) but usually nothing happens and .get(id) returns the old values

    Maybe you can update the docs to be a little more clear? This is a great lib

    opened by falafflepotatoe 15
  • best way to clone node & have two instances of a controller running?

    best way to clone node & have two instances of a controller running?

    I'm trying to create two instances of 1 widget Box; is this the best way?

    Also bug report? Its not working.

    <div id="appwrapper">
        <div id="app">
            <div data-ref="view"></div>
        </div>
    </div>
    
    var Box = Controller.extend({
        init:function(){},
        render:function(){
            return {
                view: { html: 'adsfasdfdsfadfsa' }
            }
        },
        click:function(){},
    })
    
    window.app = new Box({view: 'appwrapper' })
    window.app2 = new Box({ view: 'appwrapper' })
    

    // nothing is displayed and no errors are given

    // window.app = new Box({view: document.getElementById('app') }) // works

    from the docs: If options.view is a string, then it is used to locate the DOM node by ID and clone its first child. This is much faster than doing templating and parsing templates using innerHTML.

    not sure if its not working or im doing it wrong. Chrome 33 on linux.

    opened by falafflepotatoe 8
  • Collection.Find method (probable) bug

    Collection.Find method (probable) bug

    Hi Artemi. I was trying to find a model in a collection, passing some of its attributes, but without the id. Contrary to my expectations, the collection's find method yielded "undefined", although I was certain that there was the model whose attributes I was looking for. I think I may have found a possible issue.

    Changing (from line 80 onwards)

    isEqual: function(attr) {
        for (var key in attr) {
          if (!isEqual(attr[key], this[key])) return false;
        }
        return true;
      },
    

    To

    isEqual: function(attr) {
        for (var key in attr) {
          if (isEqual(attr[key], this[key])) return true;
        }
        return false;
      },
    

    made it possible to find a model in a collection, by passing some of its attributes (without the id).

    opened by alkaest2002 7
  • Using a model function (instead of an attribute)

    Using a model function (instead of an attribute)

    Hi, I have a function 'status' on a model that returns the status of an object based on some other model attributes (assigned_to, start_date, complete_date).

    In my render function, I'm trying to do this: render: function() { return { job_status: this.model.status }

    However, in my view I just see the toString of the 'status' function (rather than the return value of the function).

    In the docs, it says that Model#get accepts an attribute or function name.

    What am I doing wrong?

    opened by jus101 5
  • Add spm support

    Add spm support

    A nicer package manager: http://spmjs.io Documentation: http://spmjs.io/documentation

    http://spmjs.io/package/espresso.js


    It is a package manager based on Sea.js which is a popular module loader in China.

    spmjs focus in browser side. We supply a complete lifecycle managment of package by using spm.

    If you need ownership of espresso.js in spmjs, I can add it for your account after signing in http://spmjs.io.

    opened by sorrycc 2
  • docs error? init is not actually passed options

    docs error? init is not actually passed options

    it appears init is not passed options they are just set behind the scenes

    init: function(options){ console.log(options) }

    shows 'undefined'.

    i think the docs are wrong, perhaps you should also mention that you should pass an object

    opened by falafflepotatoe 1
  • support form input value, removing attributes

    support form input value, removing attributes

    I converted a small app from a self-submitting iframe that did all rendering on the server to an Espresso app. (Ended up ~150 lines coffeescript compiled to >300 lines javascript.) I needed the features added here to properly handle form elements, especially removing a disabled attribute once it was added and setting the value of form elements (selects are much easier to set this way, textareas can only be set this way).

    I think there's a case to be made for supporting false as well as null for attribute removal, as I can't think of any circumstance in which I would set an attribute to boolean false and want the result to be attribute="false", but I didn't make that further change.

    opened by midnightmonster 1
  • Large scale app questions

    Large scale app questions

    I am interested in starting a similar project based on components of backbone and react but it looks like this project might be heard in a similar direction but I have a few questions.

    1. There doesn't seem to be a router, did I just miss it? If not what are the plans for one?
    2. There isn't an example of using templates, is it possible? For later applications there is no way all the HTML can be in a single file.
    3. Why not just use react as the rendering engine? they have already addressed many issues of updating the Dom efficiently.
    opened by nnance 1
  • Better isXXX by checking [[Class]] with toString

    Better isXXX by checking [[Class]] with toString

    I think it may help to follow the path lead from other projects such as underscore, since this awesome lightweight framework is inspired by Backbone. It seems this implementation is faster on modern browsers as well. http://jsperf.com/underscore-js-istype-alternatives

    opened by jakeburden 1
Owner
TechLayer
TechLayer
MVC framework making it easy to write realtime, collaborative applications that run in both Node.js and browsers

Derby The Derby MVC framework makes it easy to write realtime, collaborative applications that run in both Node.js and browsers. Derby includes a powe

DerbyJS 4.7k Dec 31, 2022
🌟 DataFormsJS 🌟 A minimal JavaScript Framework and standalone React and Web Components for rapid development of high quality websites and single page applications.

?? Welcome to DataFormsJS! Thanks for visiting! ?? ?? ?? ?? ?? ?? 中文 (简体) 欢迎来到 DataFormsJS Español Bienvenido a DataFormsJS Português (do Brasil) Bem

DataFormsJS 156 Dec 8, 2022
A rugged, minimal framework for composing JavaScript behavior in your markup.

Alpine.js Alpine.js offers you the reactive and declarative nature of big frameworks like Vue or React at a much lower cost. You get to keep your DOM,

Alpine.js 22.5k Dec 30, 2022
A JavaScript implementation of SOM, a minimal Smalltalk for teaching and research.

ohm-som A JavaScript implementation of SOM, a minimal Smalltalk for teaching and research. Just a hobby, won't be big and professional like TruffleSOM

Patrick Dubroy 16 Jun 25, 2021
Simple and elegant component-based UI library

Simple and elegant component-based UI library Custom components • Concise syntax • Simple API • Tiny Size Riot brings custom components to all modern

Riot.js 14.7k Jan 4, 2023
: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
🙋‍♀️ 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
JavaScript UI library for data-driven web applications

Road to 2.0 The master branch has new, in-progress version of w2ui. You might want to consider 1.5 branch that is stable and supports older browsers.

Vitali Malinouski 2.4k Jan 3, 2023
An unofficial SmartThings websocket API library (alpha)

An unofficial SmartThings websocket API library (alpha) ?? Installation This is a Node.js module available through the npm registry. $ npm i -S smart-

Stephen Mendez 4 Sep 20, 2021
Formily + SemiDesign: The Awesome Components Library with Formily & Semi

Formily + SemiDesign: The Awesome Components Library with Formily & Semi

Formily Organization 12 Dec 19, 2022
Super-Resolution-CNN - web server for super-resolution CNN

Web Server for Image Super-Resolution This project showcases the Super-Resolution CNN (SRCNN). The model is pretrained following this tutorial. The or

Daniel O'Sullivan 1 Jan 3, 2022
Super minimal selector and event library

min.js A super tiny JavaScript library to execute simple DOM querying and hooking event listeners. Aims to return the raw DOM node for you to manipula

Remy Sharp 1.1k Dec 13, 2022
A super simple minimal tRPC for next-js

Typed Routes A way to have fully typed routes in next, without all the complexity of tRPC. This is more for super minimal use cases, where you don't n

Rahul Tarak 4 Dec 28, 2022
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
Gatsby-starter-minimal-blog - Typography driven, feature-rich blogging theme with minimal aesthetics.

Gatsby-starter-minimal-blog - Typography driven, feature-rich blogging theme with minimal aesthetics. Includes tags/categories support and extensive features for code blocks such as live preview, line numbers, and line highlighting.

Priya Chakraborty 0 Jan 29, 2022
We.js, extensible Node.js MVC framework - CLI

We.js ;) We.js is a extensible node.js MVC framework For information and documentation see: http://wejs.org This repository (wejs/we) have the We.js C

We.js 208 Nov 10, 2022
MVC framework making it easy to write realtime, collaborative applications that run in both Node.js and browsers

Derby The Derby MVC framework makes it easy to write realtime, collaborative applications that run in both Node.js and browsers. Derby includes a powe

DerbyJS 4.7k Dec 31, 2022
We.js, extensible Node.js MVC framework - CLI

We.js ;) We.js is a extensible node.js MVC framework For information and documentation see: http://wejs.org This repository (wejs/we) have the We.js C

We.js 208 Nov 10, 2022
AngularJS SPA Template for Visual Studio is a project skeleton for a simple single-page web application (SPA) built with AngularJS, Bootstrap, and ASP.NET (MVC, Web Api, SignalR).

AngularJS SPA Template for Visual Studio This project is a skeleton for a simple single-page web application (SPA) built on top of the: AngularJS 1.2.

Kriasoft 105 Jun 18, 2022
Realtime MVC Framework for Node.js

Website Get Started Docs News Submit Issue Sails.js is a web framework that makes it easy to build custom, enterprise-grade Node.js apps. It is design

Balderdash 22.4k Dec 31, 2022