Skip to content

Commit 194dd54

Browse files
committed
Version 1.0.0
0 parents  commit 194dd54

15 files changed

Lines changed: 927 additions & 0 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bower_components
2+
node_modules
3+
deps
4+
font

.npmignore

Whitespace-only changes.

Gulpfile.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
3+
var gulp = require('gulp');
4+
var sourcemaps = require('gulp-sourcemaps');
5+
var plugins = require('gulp-load-plugins')();
6+
var gutil = require('gulp-util');
7+
var shell = require('gulp-shell');
8+
9+
var build = {
10+
filename: 'neurosync-firebase.js',
11+
minified: 'neurosync-firebase.min.js',
12+
output: './build/',
13+
include: [
14+
'./src/neurosync-firebase.js'
15+
]
16+
};
17+
18+
var executeMinifiedBuild = function(props)
19+
{
20+
return function() {
21+
return gulp
22+
.src( props.include )
23+
.pipe( sourcemaps.init() )
24+
.pipe( plugins.concat( props.minified ) )
25+
.pipe( plugins.uglify().on('error', gutil.log) )
26+
.pipe( sourcemaps.write('.') )
27+
.pipe( gulp.dest( props.output ) )
28+
;
29+
};
30+
};
31+
32+
var executeBuild = function(props)
33+
{
34+
return function() {
35+
return gulp
36+
.src( props.include )
37+
.pipe( plugins.concat( props.filename ) )
38+
.pipe( gulp.dest( props.output ) )
39+
;
40+
};
41+
};
42+
43+
gulp.task( 'js:min', executeMinifiedBuild( build ) );
44+
gulp.task( 'js', executeBuild( build ) );
45+
gulp.task( 'default', ['js:min', 'js']);

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# neurosync-firebase
2+
3+
A neurosync binding to firebase - implementing Neuro.rest & Neuro.live.
4+
5+
The easiest way to install is by using bower via `bower install neurosync-firebase`.

bower.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "neurosync-firebase",
3+
"version": "1.0.0",
4+
"homepage": "https://github.com/ClickerMonkey/neurosync-firebase",
5+
"authors": [
6+
"Philip Diffenderfer <[email protected]>"
7+
],
8+
"description": "A neurosync binding to firebase - implementing Neuro.rest & Neuro.live",
9+
"main": "build/neurosync-firebase.js",
10+
"keywords": [
11+
"javascript",
12+
"orm",
13+
"offline",
14+
"realtime",
15+
"neurosync",
16+
"firebase"
17+
],
18+
"license": "MIT",
19+
"ignore": [
20+
"**/.*",
21+
"node_modules",
22+
"bower_components",
23+
"test",
24+
"tests"
25+
],
26+
"dependencies": {
27+
"firebase": "~2.3.2"
28+
}
29+
}

build/neurosync-firebase.js

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
(function(Firebase, global, undefined)
2+
{
3+
4+
var cache = {};
5+
6+
var Neuro_live = Neuro.live;
7+
var Neuro_rest = Neuro.rest;
8+
9+
Neuro.firebase = function(url)
10+
{
11+
return url in cache ? cache[ url ] : cache[ url ] = new Firebase( url );
12+
};
13+
14+
if ( !Neuro.liveSet )
15+
{
16+
Neuro.live = function(database)
17+
{
18+
if ( !database.api )
19+
{
20+
return Neuro_live.call( this, database );
21+
}
22+
23+
var fire = database.api;
24+
25+
function handleSave(snapshot)
26+
{
27+
var data = snapshot.val();
28+
var key = snapshot.key();
29+
30+
database.liveSave( key, data );
31+
}
32+
33+
function handleRemove(snapshot)
34+
{
35+
var data = snapshot.val();
36+
var key = snapshot.key();
37+
38+
database.liveRemove( key );
39+
}
40+
41+
fire.on( 'child_added', handleSave );
42+
fire.on( 'child_changed', handleSave );
43+
fire.on( 'child_removed', handleRemove );
44+
45+
return {
46+
firebase: fire,
47+
save: Neuro.noop,
48+
remove: Neuro.noop
49+
};
50+
};
51+
52+
Neuro.liveSet = true;
53+
}
54+
55+
if ( !Neuro.restSet )
56+
{
57+
Neuro.rest = function(database)
58+
{
59+
if ( !database.api )
60+
{
61+
return Neuro_rest.call( this, database );
62+
}
63+
64+
var fire = database.api;
65+
66+
function createCallback(success, failure)
67+
{
68+
return function onOperation(error)
69+
{
70+
if ( error )
71+
{
72+
failure( {}, error );
73+
}
74+
else
75+
{
76+
success( {} );
77+
}
78+
};
79+
}
80+
81+
function clearUndefined(obj)
82+
{
83+
for (var prop in obj)
84+
{
85+
if ( obj[ prop ] === undefined )
86+
{
87+
delete obj[ prop ];
88+
}
89+
}
90+
}
91+
92+
return {
93+
94+
firebase: fire,
95+
96+
all: function( success, failure )
97+
{
98+
if ( Neuro.forceOffline )
99+
{
100+
return failure( [], 0 );
101+
}
102+
103+
function onAll(snapshot)
104+
{
105+
var data = snapshot.val();
106+
var models = [];
107+
108+
for (var key in data)
109+
{
110+
var model = data[ key ];
111+
112+
if ( Neuro.isObject( model ) )
113+
{
114+
models.push( model );
115+
}
116+
}
117+
118+
success( models );
119+
}
120+
121+
function onAllError(error)
122+
{
123+
failure( [], error.code );
124+
}
125+
126+
fire.once( 'value', onAll, onAllError );
127+
},
128+
129+
get: function( model, success, failure )
130+
{
131+
if ( Neuro.forceOffline )
132+
{
133+
return failure( {}, 0 );
134+
}
135+
136+
function onGet(snapshot)
137+
{
138+
var data = snapshot.val();
139+
140+
success( data );
141+
}
142+
143+
function onGetError(error)
144+
{
145+
failure( {}, error.code );
146+
}
147+
148+
file.child( model.$key() ).once( 'value', onGet, onGetError );
149+
},
150+
151+
create: function( model, encoded, success, failure )
152+
{
153+
if ( Neuro.forceOffline )
154+
{
155+
return failure( {}, 0 );
156+
}
157+
158+
clearUndefined( encoded );
159+
160+
fire.child( model.$key() ).set( encoded, createCallback( success, failure ) );
161+
},
162+
163+
update: function( model, encoded, success, failure )
164+
{
165+
if ( Neuro.forceOffline )
166+
{
167+
return failure( {}, 0 );
168+
}
169+
170+
clearUndefined( encoded );
171+
172+
fire.child( model.$key() ).update( encoded, createCallback( success, failure ) );
173+
},
174+
175+
remove: function( model, success, failure )
176+
{
177+
if ( Neuro.forceOffline )
178+
{
179+
return failure( {}, 0 );
180+
}
181+
182+
fire.child( model.$key() ).remove( createCallback( success, failure ) );
183+
},
184+
185+
query: function( query, success, failure )
186+
{
187+
success( [] );
188+
}
189+
190+
};
191+
192+
};
193+
194+
Neuro.restSet = true;
195+
}
196+
197+
})( Firebase, this );

build/neurosync-firebase.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/neurosync-firebase.min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/tasks/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Running the example
2+
3+
Goto index.html

0 commit comments

Comments
 (0)