Giter Club home page Giter Club logo

fin's Introduction

Run the demo

git clone git://github.com/marcuswestin/fin.git
cd fin
sudo npm install .
sudo npm install ui
./bin/build
node demo/run-server.js
# Go to http://localhost:1234/

Commandline

Install fin npm install fin

Run the server fin localhost 8080

Now fire up your browser to localhost/[path to fin]/demo, or try out the Key/Value API example below

Key/Value API

<script src="http://localhost:8080/fin-api.js"></script>
<script>
fin.connect(function() {
	// Create items
	fin.create({ name: 'john' }, function(friendID) {
		fin.create({ name: 'marcus' }, function(marcusID) {
			fin.set(marcusID, 'friend', friendID)

			// Observe item properties
			fin.observe(marcusID, 'name', function(mutation) { console.log("Marcus' name is", mutation.value) })
			fin.observe(marcusID, 'friend.name', function(mutation) { console.log("Marcus' friend's name is", mutation.value) })
		})

		// Mutate item properties
		var names = ['john', 'david', 'lars', 'henrik', 'johannes', 'mark']
		setInterval(function() {
			fin.set(friendID, 'name', names[Math.floor(Math.random() * names.length)])
		}, 1000 + Math.ceil(Math.random() * 3000))
	})
})
</script>

ORM API

<script src="http://localhost:8080/fin-models-api.js"></script>
<script>
fin.connect(function() {
	// Declare schema
	fin.models.process({
		"Global": {
			"messages": { id:1, type:'List', of:'Message' }
		},
		"Message": {
			"text": { id:1, type:'Text' },
			"from": { id:2, type:'User' }
		},
		"User": {
			"name": { id:1, type:'Text' },
			"age":  { id:2, type:'Number' }
		}
	})

	// Instantiate models
	var user = new fin.models.User(1) // user with ID 1
	var message = new fin.models.Message({ text:'Hi!', from:user })
	fin.models.global.messages.push(message)
	
	// Observe model properties
	fin.models.global.messages.on('push', function(message) {
		message.from.name.observe(function(name) { console.log('message from', name) })
		message.text.observe(function(text) { console.log('message text is',  text) })
	})
</script>

Engines

Fin uses pluggable engines for storage and pubsub. You can build your own engine, or use one that comes with fin.

var fin = require('fin'), engine = require('fin/engines/development')
fin.start('localhost', 8080, engine)

The "development" engine holds all data and handles subscriptions in node process memory. It's great for development since you do not need to install a storage system and a pubsub system to get started. In production, you should use a more scalable engine, e.g. the redis engine:

Install redis sudo make install-redis Start redis server redis-server Start fin server var fin = require('fin'), redisEngine = require('fin/engines/development') fin.start('production.com', 8080, redisEngine)

fin's People

Contributors

jfhbrook avatar marcuswestin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  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.