Code Monkey home page Code Monkey logo

wings-feathers's Introduction

Welcome to Wings-Feathers!


A FeathersJS 4-Way reactive data sync for any frontend framework

  • DOM / UI (HTML)
  • Data / State (Javascript)
  • Local Storage (Offline)
  • Backend/Database (Cloud)

Join and support our Community
Web and Mobile Developers PH
[ Facebook Page | Group ]

Installation

npm install wings-feathers

or

yarn add wings-feathers

Usage

import wings from 'wings-feathers'
// const wings = require('wings-feathers').default

let app = wings('http://localhost:3030')

let messagesSrvc = app.wingsService('messages')

messagesSrvc.on('dataChange', (messages) => {
  console.log(messages)
})

messagesSrvc.init()

app.wingsService(serviceName, params, config)

Returns a wingsService <object>

Param Type Description
serviceName <string> Name of service
params.query <object> ( Optional ) Refer to Feathers Querying
config <object> ( Optional ) Configuration of wingsService <object>
config.channels <array> ( Optional ) Array of channel objects

params.query <object>

Refer to Feathers Querying

/* example records
  [
    { text: 'Hello', read: true, roomId: 1, nested: { prop: 'xander' } },
    { text: 'World', read: false, roomId: 2, nested: { prop: 'ford' } }
  ]
*/

let serviceName = 'message'

let params = {
  query: {
    read: false,
    roomId: 2
  }
}

let messagesSrvc = app.wingsService(serviceName, params)

messagesSrvc.on('dataChange', (messages) => {
  console.log(messages)
  // [ { text: 'World', read: false, roomId: 2, nested: { prop: 'ford' } } ]
})

config <object>

Property Type Default Description
debug <boolean> false Logs all events init, created, removed, patched, updated, loadMore, reset
newDataPosition <string> 'end' Add new items to the start or end of an array
paginate <boolean> false Enable pagination based on $limit. **default is 10 records per page
channels <array> [] Refer to channels
let config = {
  debug: true,
  newDataPosition: 'start',
  paginate: true,
  channels: []
} 

let messagesSrvc = app.wingsService(serviceName, params, config)

config.channels <array> and channel <object>

Channels determine which records to receive that passes the prop === value .

Property Type Description
prop <string> Name of record's property
value `<string number
value <function> callback accepts (val, message) arguments for custom test. **Must return a boolean value
/* example records
  [
    { text: 'Hello', read: true, roomId: 1, nested: { prop: 'xander' } },
    { text: 'World', read: false, roomId: 2, nested: { prop: 'ford' } }
  ]
*/

let config = {
  channels: [
    { prop: 'roomId', value: 2},
    { prop: 'nested.prop', value: 'ford'},
    { prop: 'nested', value: (val) => val.prop === 'ford' }
  ]
}

let messagesSrvc = app.wingsService(serviceName, params, config)

You may use dot notation in prop as reference into the object's property

reset(params, config)

set new params, config and triggers init method

let params = {
  query: {
    read: false,
    roomId: 2
  }
}

let config = {
  debug: true,
  newDataPosition: 'start',
  paginate: true,
  channels: []
}

messagesSrvc.reset(params, config)

loadMore()

loads more data based on $skip = ( page + 1 ) * $limit

messagesSrvc.loadMore()

loadAll()

loads all data based on ($skip = page * $limit) * pages

messagesSrvc.loadAll()

loadPage(page)

loads the based on $skip = page * $limit

messagesSrvc.loadPage(2)

destroy()

destroys all listners created by .on(eventName, listener) function

messagesSrvc.destroy()

Join and support our Community
Web and Mobile Developers PH
[ Facebook Page | Group ]

wings-feathers's People

Contributors

trinly01 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

soltrinox

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.