Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
when gluing stuff together for the map, don't overwrite synclets ever…
…y time, they care about themselves too much, fixes #874
- Loading branch information
Showing
1 changed file
with
21 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,25 @@ exports.providers = function(types) { | |
return services; | ||
}; | ||
|
||
// lutil.extend is YOUR MOM | ||
This comment has been minimized.
Sorry, something went wrong. |
||
function fuckingMerge(alive, dead) | ||
This comment has been minimized.
Sorry, something went wrong.
othiym23
Member
|
||
{ | ||
// we have to intelligently merge synclets array! | ||
if(dead.synclets){ | ||
if(!alive.synclets) alive.synclets = []; | ||
var ndx = {}; | ||
for(var i = 0; i < alive.synclets.length; i++) ndx[alive.synclets[i].name] = alive.synclets[i]; | ||
for(var i = 0; i < dead.synclets.length; i++) { | ||
var s = dead.synclets[i]; | ||
if(ndx[s.name]) Object.keys(s).forEach( function(key){ ndx[s.name][key] = s[key] } ); | ||
if(!ndx[s.name]) alive.synclets.push(s); | ||
} | ||
} | ||
// everything else dumb copy | ||
Object.keys(dead).forEach(function(key){ | ||
if(key != "synclets") alive[key] = dead[key]; | ||
}); | ||
} | ||
|
||
// update or install this file into the map | ||
exports.mapUpsert = function (file) { | ||
|
@@ -139,7 +158,7 @@ exports.mapUpsert = function (file) { | |
// synclets are in their own file, extend them in too | ||
var sync = path.join(lconfig.lockerDir, path.dirname(file),"synclets.json"); | ||
if(path.existsSync(sync)) { | ||
js = lutil.extend(js, JSON.parse(fs.readFileSync(sync, 'utf8'))); | ||
fuckingMerge(js, JSON.parse(fs.readFileSync(sync, 'utf8'))); | ||
} | ||
} catch (E) { | ||
logger.error("failed to upsert "+file+" due to "+E); | ||
|
@@ -154,7 +173,7 @@ exports.mapUpsert = function (file) { | |
// if it exists already, merge it in and save it | ||
if(serviceMap[js.handle]) { | ||
logger.verbose("updating "+js.handle); | ||
serviceMap[js.handle] = lutil.extend(serviceMap[js.handle], js); | ||
fuckingMerge(serviceMap[js.handle], js); | ||
exports.mapReload(js.handle); | ||
// if it's running and updated, signal it to shutdown so new code/config is run at next request | ||
if(js.pid) try { | ||
|
1 comment
on commit cf418b9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we need some specific functions that we understand and fit the usage patterns of our data, rather than hacking up jQuery code and random one-off methods.
Can you maybe replace this with something that explains why this function exists / what led to it being created?