How to use the falcor.Model function in falcor

To help you get started, we’ve selected a few falcor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ParabolInc / falcor-saddle / test / utils / test-server.js View on Github external
import Falcor from 'falcor';
import bodyParser from 'body-parser';
import HttpDataSource from 'falcor-http-datasource';

const SERVER_PORT = 15649;
const FALCOR_MODEL = '/model.json';
const FALCOR_MODEL_URL = `http://localhost:${SERVER_PORT}${FALCOR_MODEL}`;

let instance = null;

// Initialize Falcor HTTP client:
const testModel = new Falcor.Model(
	{ source: new HttpDataSource(FALCOR_MODEL_URL) }
);

const batchTestModel = new Falcor.Model(
	{ source: new HttpDataSource(FALCOR_MODEL_URL) }
);

export class TestServer {
	constructor() {
    if (!instance) {
			instance = this;
			this.app = express();
    }
    return instance;
	}

	refresh() {
		this.app = express();
		return this.app;
	}
github rsamec / react-designer-core / remote.js View on Github external
//                });
//
//                return results
//            }
//        }
//    ]);
//}));

//console.log(JSON.stringify(yearInvoices.invoicesById,null,2));
app.use('/mfcr.json',falcorExpress.dataSourceRoute(function (req, res) {
    return mfcrDataSource;
}));


var dataSource =
    new falcor.Model({
        cache: {
            todos: [
                { $type: "ref", value: ['todosById', 1450000365] },
                { $type: "ref", value: ['todosById', 54] },
                { $type: "ref", value: ['todosById', 97] },
                { $type: "ref", value: ['todosById', 197] }
            ],
            todosById: {
                "1450000365": {
                    name: 'get milk from corner store',
                    done: false,
                    prerequisites: [
                        { $type: "ref", value: ['todosById', 54] },
                        { $type: "ref", value: ['todosById', 97] }
                    ]
                },
github thegazelle-ad / gazelle-server / src / client-scripts / admin-client.js View on Github external
import { ModalProvider } from 'components/admin/hocs/modals/ModalProvider';
import HttpDataSource from 'falcor-http-datasource';
import { MuiThemeProvider } from 'material-ui';
import { Provider as FalcorProvider } from 'react-falcor';

/** We need to initialize the logger */
import { initializeLogger } from 'lib/logger';

// We start with window.alert as our alert function but later will replace
// it with our alert function from ModalProvider
initializeLogger(true, window.alert);

// Set app ready so falcor doesn't try to load from cache
setAppReady();

const clientModel = new falcor.Model({
  source: new HttpDataSource('/model.json'),
});

ReactDOM.render(
  
    
      
        
      
    
  ,
  document.getElementById('main'),
github thegazelle-ad / gazelle-server / src / server.js View on Github external
// Merging pathsets
  falcorPaths = falcorPaths.reduce((currentPathSets, nextPathSet) => {
    if (nextPathSet[0] instanceof Array) {
      return currentPathSets.concat(nextPathSet);
    }
    currentPathSets.push(nextPathSet);
    return currentPathSets;
  }, []);

  // create a new model for this specific request
  // the reason we do this is so that the serverModel
  // cache won't expire records we need during the unlikely
  // event of heavy concurrent and unique traffic
  // And also it creates the minimum set of data we can send down
  // to the client and reload on the falcor there
  const localModel = new falcor.Model({ source: serverModel.asDataSource() });

  // If the component doesn't want any data
  if (
    !falcorPaths ||
    falcorPaths.length === 0 ||
    falcorPaths[0].length === 0 &&
    falcorPaths.length === 1
  ) {
    return new Promise((resolve) => {
      resolve(
        buildMainHtmlString(
          renderToString(
github ustccjw / tech-blog / model / index.js View on Github external
import falcor from 'falcor'
import HttpDataSource from 'falcor-http-datasource'

let url = '/model.json'
if (process.env.NODE_ENV === 'development') {
	url = 'http://127.0.0.1:3000/model.json'
}

// dataModel 按对象实体划分
export const dataModel = new falcor.Model({
	source: new HttpDataSource(url),
})

// uiModel 按 route component 划分
export const uiModel = new falcor.Model({
	cache: {
		articleList: {
			page: 1,
		},
	},
})

if (global.dataCache) {
	dataModel.setCache(global.dataCache)
}
github Netflix / falcor-router / test / integration / get.spec.js View on Github external
it('should perform reference following.', function(done) {
        var router = new R(
            Routes().Videos.Integers.Summary().concat(
              Routes().Genrelists.Integers()
            )
        );
        var model = new falcor.Model({
            source: router
        });
        var called = false;

        model.get(['genreLists', 0, 'summary']).subscribe(
            function (x) {
                called = true;
                expect(x).to.deep.equals({
                    json: {
                        genreLists: {
                            0: {
                                summary: {
                                    title: 'Some Movie 0'
                                }
                            }
                        }
github ustccjw / tech-blog / client / store / configureStore.js View on Github external
import { combineReducers, applyMiddleware, createStore, compose } from 'redux'
import { createFalcorMiddleware, falcorReducer } from 'redux-falcor'
import falcor from 'falcor'
import { reduxReactRouter, routerStateReducer } from 'redux-router'
import { createHistory } from 'history'
import promiseMiddleware from 'redux-promise'
import { warningMiddleware } from '../middleware'
import * as reducers from '../reducer'
import routes from '../route'

const reducer = combineReducers({
	...reducers,
	entities: falcorReducer,
	router: routerStateReducer,
})
const model = new falcor.Model({
	source: new falcor.HttpDataSource('/model.json'),
})

let finalCreateStore = null
if (process.env.NODE_ENV === 'development') {
	const devTool = require('../dev-tool')
	const { persistState } = require('redux-devtools')
	finalCreateStore = compose(
		applyMiddleware(promiseMiddleware, createFalcorMiddleware(model),
			warningMiddleware),
		reduxReactRouter({
			routes,
			createHistory,
		}),
		devTool.instrument(),
		persistState(window.location.href.match(
github mapillary / mapillary-js / src / api / ModelCreator.ts View on Github external
public createModel(clientId: string, token?: string): falcor.Model {
        const configuration: HttpDataSourceConfiguration = {
            crossDomain: true,
            withCredentials: false,
        };

        if (token != null) {
            configuration.headers = { "Authorization": `Bearer ${token}` };
        }

        return new falcor.Model({
            maxSize: 16 * 1024 * 1024,
            source: new XmlHttpSource(Urls.falcorModel(clientId), configuration),
        });
    }
}
github thegazelle-ad / gazelle-server / src / lib / falcor / model.js View on Github external
import falcor from "falcor"

const model = new falcor.Model({
  cache: {
    pages: [
      {
        title: "Page 0 title",
        body: "Page 0 body"
      },
      {
        title: "Page 1 title",
        body: "Page 1 body"
      },
      {
        title: "Page 2 title",
        body: "Page 2 body"
      }
    ]
  }