Giter Site home page Giter Site logo

patch-profile's Introduction

Patch-profile

A module for editing your (or other people's) profiles in patch-* family apps. Edits names or images.

You'll need to understand depject (a module for a different way of managing dependency injection), and for the example below, depnest - a lazy way to write nested objects quickly.

Example

const nest = require('depnest')
const { h } = require('mutant')

exports.gives = nest('app.page.userEdit')

exports.needs = nest({
  'about.page.edit': 'first',
  'history.sync.push': 'first',
})

exports.create = (api) => {
  return nest('app.page.userEdit', userEdit)

  function userEdit (location) {
    // location is an object { feed, page: 'userEdit' } 

    const options = { feed: location.feed }
    const callback = (err, didEdit) => {
      if (err) throw new Error ('Error editing profile', err) 

      if (didEdit) console.log('Profile updated!')
      // go back to the users profile
      api.history.sync.push({ page: 'userShow', feed })
    }

    return h('Page -userEdit', {}, [
      h('div.container', [
        api.about.page.edit(options, callback)
      ])
    ])
  }
}

API

about.page.edit

(options=object, callback=function)

Where target is of the form { feed='@....', labels=object }

labels (optional) can be used to override labels for translations: { name, image, cancel, save } callback (optional) will be called after a user confirms or cancels changes. It has signature (err, didEdit=boolean), where didEdit == true if an edit was published.

styles.mcss

Patch-profile exports basic mcss styles. See Patchbay for examples of how this can be integrated into an app.

patch-profile's People

Contributors

mixmix avatar zmarouf avatar

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.