1amageek / ballcap.ts

Cloud Firestore support library for admin. 🧢
107 stars 13 forks source link

Doc.data () does not set values ​​in additional fields #13

Open onota0318 opened 4 years ago

onota0318 commented 4 years ago

※All are translated from Japanese into English by Google Translate.

Maybe my usage is wrong...

Description

Expection

If you pass the value to Field and call save () method, the value is registered in firestore field

import "reflect-metadata";
import { Field, Doc } from "@1amageek/ballcap";

export class Product extends Doc {
    @Field 
    public providerType: string;
}
    const product = new Product();
    product.providerType = "ABC";
    await product.save();
results

actual field providerType is null・・・

Question

Doc.data() is got the following results.

Object {
  "configurable": true,
  "enumerable": true,
  "value": "ABC",
  "writable": true,
}

https://github.com/1amageek/ballcap.ts/blob/master/web/src/Model.ts#L90

descripter.get isn't applicable.

It works as expected.

//            if (descriptor && descriptor.get) {
            if (descriptor && descriptor.get) {
                const value = descriptor.get();
                data[codingKey] = this._encode(value, option);
            }
★            else if (descriptor && descriptor.value) {
                data[codingKey] = this._encode(descriptor.value, option);
            }

I have no idea if my usage is wrong or if I need to modify the library...

1amageek commented 4 years ago

@onota0318 Thank you for your message.

I think there is a problem in your tsconfig.json. If you are using webpack, try the readme settings.

onota0318 commented 4 years ago

@1amageek

Thank you for your reply. I am using Expo this time and refer to example/with-expo

expo : 36.0.2

tsconfig.json

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "jsx": "react-native",
    "target": "esnext",
    "lib": ["dom", "esnext"],
    "moduleResolution": "node",
    "module": "commonjs",
    "noEmit": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "forceConsistentCasingInFileNames": true,
    "baseUrl": "./",
    "paths": {
      "@Config/*": ["./src/config/*"],
                   〜
    },
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}

babel.config.js

module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: [
      [
        "module-resolver",
        {
          root: ["./"],
          alias: {
            "@Config": "./src/config",
                   〜
          },
        },
      ],
    ],  
  };
};

I am check the configuration again.

1amageek commented 4 years ago

@onota0318 連絡遅れてすみません。 日本語でいいですよ!

今の環境はReactですか?

onota0318 commented 4 years ago

@1amageek (日本語だと大変助かります・・・ありがとうございます😂)

今の環境は ReactNative(expo) です!