Git Product home page Git Product logo

ossicle's Introduction

#Samples about Backbone.js

##Backbone.sync + LocalStorage

This is a simple module of localStorage based persistence to override Backbone.sync with ability to use different kinds of models with same keys (ie : "human|001", "doc|001", ...).

**Use : **

  • include backbone-sync-localstorage.js

  • Model and Collection must have a property storeName :

      window.Human =  Backbone.Model.extend({
          storeName : "humansDB"
      });
    
      window.Humans =  Backbone.Collection.extend({
          model : Human,
          storeName : "humansDB"
      });
    
  • key storage of a model is calculated like that : storeName + "|" + model.id

  • then you can do that :

      myModel.save()              // save model to local storage
      myModel.fetch()             // get model from local storage
      myModel.destroy()           // delete model from local storage
    
      myModelsCollection.fetch()  // load all models from local storage
    

##Backbone.sync + GitHub Api

It's a "POC". Goal : to display a few pages (markdown format) stored on a GitHub repository.

The main idea is :

  • you write your text in a markdown format.
  • a webapp (HTML+JS), connects to your GitHub repository and is able to display your posts to HTML.
  • you can install it on git-pages, or to any hoster and even locally.

Dependencies

###How to setup ?

  1. create a GitHub repository with a posts directory (or an other name)

  2. copy "somewhere" these files : https://github.com/k33g/ossicle :

     .
     |-- css
     |   `-- style.css
     |-- js
     |   `-- backbone.sync
     |       |-- backbone-sync-github.js  /* override Backbone.sync */
     |   `-- vendor
     |       |-- backbone-min.js
     |       |-- github.js
     |       |-- showdown.js
     |       |-- underscore-min.js
     |       `-- zepto.min.js
     |-- bb-github-api.js
     `-- index-bb-github-api.html
    
  3. Edit bb-github-api.js : you have to set the gitHubStorage of the Backbone.Collection

     window.Posts = Backbone.Collection.extend({
         model : Post,
         initialize : function() {
             var that = this;
             that.launch = arguments[1];
             //Set the "gitHub storage"
             this.gitHubStorage = new Store('k33g','ossicle','master','posts',
                 function(){
                     that.fetch({ result : function() {
                     that.launch(); /* launched when loaded */
                 }
             });
         });
         }
     });
    

Use : this.gitHubStorage = new Store(github_user_name, github_project_name, branch_name, directory_name, callback_function);

That's all.

ossicle's People

Contributors

k33g avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.