feathersjs-ecosystem / feathers-localstorage

A client side service based on feathers-memory that persists to LocalStorage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Values of Services are Being Mixed

frastlin opened this issue · comments

Steps to reproduce

Create a project with feathers and feathers-localStorage installed and run the following code:

const feathers = require('@feathersjs/feathers')
const app = feathers()
const feathers_localStorage = require('feathers-localstorage')
const service = feathers_localStorage({
	storage: window.localStorage,
	name: 'mapping',
})

//services for this app
app.use('countries', service)
app.use('regions', service)
app.use('cities', service)

const countries = app.service('countries')
const regions = app.service('regions')
const cities = app.service('cities')

async function removeValues(){
	await countries.remove(null, {})
	await regions.remove(null, {})
	await cities.remove(null, {})
}

async function createValues(){
	await countries.create([{"continent":"EU","capital":"Andorra la Vella","languages":"ca","geonameId":3041565,"south":42.42849259876837,"isoAlpha3":"AND","north":42.65604389629997,"fipsCode":"AN","population":"84000","east":1.7865427778319827,"isoNumeric":"020","areaInSqKm":"468.0","countryCode":"AD","west":1.4071867141112762,"countryName":"Andorra","continentName":"Europe","currencyCode":"EUR","id":0},{"continent":"AS","capital":"Abu Dhabi","languages":"ar-AE,fa,en,hi,ur","geonameId":290557,"south":22.633329391479492,"isoAlpha3":"ARE","north":26.08415985107422,"fipsCode":"AE","population":"4975593","east":56.38166046142578,"isoNumeric":"784","areaInSqKm":"82880.0","countryCode":"AE","west":51.58332824707031,"countryName":"United Arab Emirates","continentName":"Asia","currencyCode":"AED","id":1},{"continent":"AS","capital":"Kabul","languages":"fa-AF,ps,uz-AF,tk","geonameId":1149361,"south":29.377472,"isoAlpha3":"AFG","north":38.483418,"fipsCode":"AF","population":"29121286","east":74.879448,"isoNumeric":"004","areaInSqKm":"647500.0","countryCode":"AF","west":60.478443,"countryName":"Afghanistan","continentName":"Asia","currencyCode":"AFN","id":2},{"continent":"NA","capital":"St. John's","languages":"en-AG","geonameId":3576396,"south":16.996979,"isoAlpha3":"ATG","north":17.729387,"fipsCode":"AC","population":"86754","east":-61.672421,"isoNumeric":"028","areaInSqKm":"443.0","countryCode":"AG","west":-61.906425,"countryName":"Antigua and Barbuda","continentName":"North America","currencyCode":"XCD","id":3},{"continent":"NA","capital":"The Valley","languages":"en-AI","geonameId":3573511,"south":18.160292974311673,"isoAlpha3":"AIA","north":18.276901971658063,"fipsCode":"AV","population":"13254","east":-62.96655544577948,"isoNumeric":"660","areaInSqKm":"102.0","countryCode":"AI","west":-63.16808989603879,"countryName":"Anguilla","continentName":"North America","currencyCode":"XCD","id":4},{"continent":"EU","capital":"Tirana","languages":"sq,el","geonameId":783754,"south":39.6448624829142,"isoAlpha3":"ALB","north":42.6611669383269,"fipsCode":"AL","population":"2986952","east":21.0574334835312,"isoNumeric":"008","areaInSqKm":"28748.0","countryCode":"AL","west":19.2639112711741,"countryName":"Albania","continentName":"Europe","currencyCode":"ALL","id":5},{"continent":"AS","capital":"Yerevan","languages":"hy","geonameId":174982,"south":38.841972,"isoAlpha3":"ARM","north":41.301834,"fipsCode":"AM","population":"2968000","east":46.6289052796227,"isoNumeric":"051","areaInSqKm":"29800.0","countryCode":"AM","west":43.44978000000003,"countryName":"Armenia","continentName":"Asia","currencyCode":"AMD","id":6},{"continent":"AF","capital":"Luanda","languages":"pt-AO","geonameId":3351879,"south":-18.042076,"isoAlpha3":"AGO","north":-4.376826,"fipsCode":"AO","population":"13068161","east":24.082119,"isoNumeric":"024","areaInSqKm":"1246700.0","countryCode":"AO","west":11.679219,"countryName":"Angola","continentName":"Africa","currencyCode":"AOA","id":7}])
	await regions.create([{"adminCode1":"01","lng":"16.41667","geonameId":2781194,"toponymName":"Burgenland","countryId":"2782113","fcl":"A","population":281022,"countryCode":"AT","name":"Burgenland","fclName":"country, state, region,...","adminCodes1":{"ISO3166_2":"1"},"countryName":"Austria","fcodeName":"first-order administrative division","adminName1":"Burgenland","lat":"47.5","fcode":"ADM1"}])
	await cities.create([{"adminCode1":"06","lng":"15.27512","geonameId":8604686,"toponymName":"Politischer Bezirk Bruck-Mürzzuschlag","countryId":"2782113","fcl":"A","population":99834,"countryCode":"AT","name":"Bruck-Mürzzuschlag District","fclName":"country, state, region,...","adminCodes1":{"ISO3166_2":"6"},"countryName":"Austria","fcodeName":"second-order administrative division","adminName1":"Styria","lat":"47.4188","fcode":"ADM2"}])
}


async function checkValues(){
	const countryValues = await countries.find()
	const regionValues = await regions.find()
	const cityValues = await cities.find()
	console.log(JSON.stringify(countryValues))
	console.log(JSON.stringify(regionValues))
	console.log(JSON.stringify(cityValues))
}

removeValues()
createValues()
checkValues()

export default app

Expected behavior

There should be logged output that matches the values passed into the create function.

Actual behavior

All logged values are from the countries service.

System configuration

    "@feathersjs/feathers": "^3.1.5",
    "feathers-localstorage": "^2.0.2",
  • Firefox 52.8
  • Node 5.6.0
  • Windows 10 64 bit
  • I'm running this through a create-react-app configuration.

localStorage service instance can only be used once. Each service instance needs it's own unique name so that it doesn't write into the same place:

//services for this app
app.use('countries', feathers_localStorage({
	storage: window.localStorage,
	name: 'countries-mapping',
}))
app.use('regions', feathers_localStorage({
	storage: window.localStorage,
	name: 'regions-mapping',
}))
app.use('cities', feathers_localStorage({
	storage: window.localStorage,
	name: 'cities-mapping',
}))

That is buggy on my machine for some reason. I got empty lists for cities and regions when doing that. The localStorage was filled correctly I think, but find was returning nothing.
There should be a line in the documentation that says:
"Each service needs its own unique name." next to the name arg in the readme.
I went ahead and rolled my own for now, because it was taking too long debuggin, but if I need to switch back, for the increased search functionality, I will do so.
Thanks,

You are right, there seems to be an issue here somewhere (even if the name is different). Will look into it.

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Apologies if the issue could not be resolved. FeathersJS ecosystem modules are community maintained so there may be a chance that there isn't anybody available to address the issue at the moment. For other ways to get help see here.

I ended up rolling my own fix to this, but I would really love to have the query functionality Feathers provides with my localStorage.

Sorry, should've been marked as a bug to not go stale since I was totally able to reproduce but I'm still not sure what's causing it.

Closed via #77