Coder Social home page Coder Social logo

re-crud's Introduction

re-crud

Clojars Project CircleCI

A re-frame library for developing CRUD applications.

If your service exposes a swagger API, even better! This can consume swagger.json and perform HTTP calls to show, list, create and update resources.

example-interface-screencast

Installation

re-crud is (will be) on clojars: [re-crud "0.1.0"]

Example app

  • There is a comprehensive example-app in this repo: example-app
  • You can find a running instance of this app here: demo
  • This uses a fairly minimal CRUD web service written in Rails, deployed here: web app

Usage

Initialize re-crud soon after you initialize your re-frame app db. re-crud.core/init takes a map of service-name:config pairs.

(require '[re-crud.core :as crud])
(crud/init
 {"service-name" {:service-host "https://my-service.host"
                  :swagger-url "https://my-service.host/swagger.json"
                  :dispatch-on-ready [:on-ready]}})

The dispatch-on-ready event from service config is dispatched once re-crud has parsed the swagger spec for that service. Initialize your views after this event has been triggered.

Add crud.css in your app for styling. re-crud comes with a skin that appies MUI CSS.

Use component-generators from re-crud.components to generate the view compnent and associated events.

A simple component to retrieve and display a resource would look like this.

(def show
  (re-crud.components/show {:id     :user.show
                            :fetch  {:operation-id "getUser"}
                            :view   {:title "User info"
                                     :skin :mui
                                     :resource-name "User"}
                            :config {:service-name "my-service"}}))
  • :id identifies the component to the library
  • :fetch describes how to fetch the resource to show
  • :view configures UI details

TODO: add documentation around :load-component

Here's a slightly more involved example:

(def update
  (re-crud.components/update {:id      :user.update
                              :fetch   {:operation-id "getUser"
                                        :after (re-crud.components.utils/update-form-params-fx :user.update add-user-id)}
                              :form    {:operation-id "updateUser"}
                              :perform {:operation-id "updateUser"
                                        :after (re-crud.components.utils/create-fx
                                                #(dispatch [:goto-route :show-user {:user-id (:id %)}]))}
                              :view    {:skin :mui
                                        :resource-name "User"}
                              :config  {:service-name "my-service"}}))
  • :form will render user input fields based on the operation-id's request-schema
  • :perform describes how to send the form fields to (say) create/update resources
  • :after is an event that is triggered after fetch or perform.

Here's an example of what you''d get on creating a component

{:id                :user.show
 :events            {:fetch       :crud-fetch-user.show
                     :after-fetch :crud-after-fetch-user.show
                     :perform     :crud-perform-user.show
                     :refresh     :crud-refresh-user.show}
 :reagent-component re-crud.fn_some_generated-fn
 :state-path        [:crud-components :user.show :resource-info]}
  • :reagent-component is what you can add to your app's view
  • :events are ids of the re-frame events you can dispatch
  • :events :refresh needs to be implemented by the user

Running tests

make test (requires phantomjs)

License - Apache 2.0

Copyright 2017 Omnyway Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

re-crud's People

Contributors

shafeeq avatar rberger avatar ssrihari avatar oneness avatar

Stargazers

Qamber Abbas avatar

Watchers

 avatar James Cloos avatar  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.