Skip to content

Instantly share code, notes, and snippets.

@betocantu93
Last active July 21, 2020 14:49
Show Gist options
  • Select an option

  • Save betocantu93/4f843b83e321ea7829b1a5bc82096552 to your computer and use it in GitHub Desktop.

Select an option

Save betocantu93/4f843b83e321ea7829b1a5bc82096552 to your computer and use it in GitHub Desktop.

Revisions

  1. betocantu93 revised this gist Jul 21, 2020. 1 changed file with 1 addition and 5 deletions.
    6 changes: 1 addition & 5 deletions routes.application\.js
    Original file line number Diff line number Diff line change
    @@ -7,11 +7,7 @@ export default Route.extend({
    model() {
    console.log(this.store)
    this.store.push({
    data: {
    id: "ref:document:1",
    type: "ref:document",

    }

    })
    }
    });
  2. betocantu93 revised this gist Jul 21, 2020. 1 changed file with 1 addition and 8 deletions.
    9 changes: 1 addition & 8 deletions routes.application\.js
    Original file line number Diff line number Diff line change
    @@ -10,14 +10,7 @@ export default Route.extend({
    data: {
    id: "ref:document:1",
    type: "ref:document",
    attributes: {
    prop1: {
    a: 5,
    b: [1, 2, 3]
    },
    prop2: 10,
    prop3: ["10"]
    }

    }
    })
    }
  3. betocantu93 revised this gist Jul 21, 2020. No changes.
  4. betocantu93 revised this gist Jul 21, 2020. 2 changed files with 4 additions and 3 deletions.
    4 changes: 2 additions & 2 deletions routes.application\.js
    Original file line number Diff line number Diff line change
    @@ -8,8 +8,8 @@ export default Route.extend({
    console.log(this.store)
    this.store.push({
    data: {
    id: "1",
    type: "ref:some",
    id: "ref:document:1",
    type: "ref:document",
    attributes: {
    prop1: {
    a: 5,
    3 changes: 2 additions & 1 deletion services.m3-schema\.js
    Original file line number Diff line number Diff line change
    @@ -30,12 +30,13 @@ let computeValue = function (key, value, modelName, schemaInterface) {
    attributes: value,
    });
    }

    return value;
    };

    export default class Schema extends DefaultSchema {
    includesModel(modelName) {
    console.log(modelName)
    return RefRegExp.test(modelName);
    }

  5. betocantu93 revised this gist Jul 21, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions services.store\.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@

    export { default } from 'ember-m3/services/store';
  6. betocantu93 revised this gist Jul 21, 2020. 1 changed file with 52 additions and 0 deletions.
    52 changes: 52 additions & 0 deletions services.m3-schema\.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    import DefaultSchema from "ember-m3/services/m3-schema";

    const RefRegExp = /^ref:/;
    const EDMRegExp = /^EDM:/;

    let computeValue = function (key, value, modelName, schemaInterface) {
    if (Array.isArray(value)) {
    return null;
    }

    if (typeof value === "string" && RefRegExp.test(value)) {
    return schemaInterface.reference({
    id: value,
    type: null,
    });
    }

    if (typeof value === "string" && EDMRegExp.test(value)) {
    let [_, modelName, id] = value.split(':');
    return schemaInterface.reference({
    id,
    type: modelName,
    });
    }

    if (value !== null && typeof value === "object") {
    return schemaInterface.nested({
    id: key,
    type: value.type,
    attributes: value,
    });
    }

    return value;
    };

    export default class Schema extends DefaultSchema {
    includesModel(modelName) {
    return RefRegExp.test(modelName);
    }

    computeAttribute(key, value, modelName, schemaInterface) {
    if (Array.isArray(value)) {
    let nested = value.map((v) => {
    return computeValue(key, v, modelName, schemaInterface);
    });
    return schemaInterface.managedArray(nested);
    } else {
    return computeValue(key, value, modelName, schemaInterface);
    }
    }
    }
  7. betocantu93 created this gist Jul 21, 2020.
    5 changes: 5 additions & 0 deletions controllers.application\.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    import Controller from '@ember/controller';

    export default class ApplicationController extends Controller {
    appName = 'Ember Twiddle';
    }
    24 changes: 24 additions & 0 deletions routes.application\.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    import Route from '@ember/routing/route';
    import { inject as service } from '@ember/service';

    export default Route.extend({


    model() {
    console.log(this.store)
    this.store.push({
    data: {
    id: "1",
    type: "ref:some",
    attributes: {
    prop1: {
    a: 5,
    b: [1, 2, 3]
    },
    prop2: 10,
    prop3: ["10"]
    }
    }
    })
    }
    });
    6 changes: 6 additions & 0 deletions templates.application\.hbs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    <h1>Welcome to {{this.appName}}</h1>
    <br>
    <br>
    {{outlet}}
    <br>
    <br>
    24 changes: 24 additions & 0 deletions twiddle\.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    {
    "version": "0.17.1",
    "EmberENV": {
    "FEATURES": {},
    "_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
    "_APPLICATION_TEMPLATE_WRAPPER": true,
    "_JQUERY_INTEGRATION": true
    },
    "options": {
    "use_pods": false,
    "enable-testing": false
    },
    "dependencies": {
    "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js",
    "ember": "3.16.7",
    "ember-template-compiler": "3.16.7",
    "ember-testing": "3.16.7"
    },
    "addons": {
    "@glimmer/component": "1.0.0",
    "ember-data": "3.18.0",
    "ember-m3": "3.0.0"
    }
    }