
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
redux-rails-resource
Advanced tools
Convenient Higher Order Component for React elements utilizing the Redux-Rails middleware
Convenient Higher Order Component for React elements utilizing the Redux-Rails middleware
You can use either yarn
or npm
to install redux-rails-resource and its dependencies.
yarn add 'redux-rails-resource'
npm install 'redux-rails-resource'
redux-rails-resource has a few peer dependencies required to use the library.
If you already have these libraries listed in your app's dependencies, there's no need to install them again.
resource(resourceName: string, resourceOptions: object)(CustomComponent: ReactComponent)
The key of the corresponding resource in the redux state defined by the redux-rails
config.
This will be used as both resource
and controller
when dispatching railsAction
s
from redux-rails
. (NOTE: controller
can be explicitly set via resourceOptions
)
The argument will also be the name of the key which will wrap everything passed down from
the resource
hoc to the wrapped component.
index
call on componentDidMount
. The sibling queryParams
attribute will be passed as an argument if definedindex
call if autoload
is truecontroller
for railsActions
.
resource
propsrailsActions
. This may be more performant if the component does not need access to state.import { resource, resourceProps } from 'redux-rails-resource'
@resource('comments')
class CommentSection extends Component {
static propTypes = {
comments: resourceProps.collection
}
componentDidMount() {
// GET request to /comments?deleted=false
// Stores the result in redux and updates this component's models
this.props.comments.index({ queryParams: { deleted: false } })
}
handleCreate = (commentAttributes) => {
// POST request to /comments
// The body of the post request will be JSON string of commentAttributes
this.props.comments.create(commentAttributes)
}
render() {
const { models } = this.props.comments
return (
<div>
<NewCommentForm onCreate={this.handleCreate} />
<CommentList comments={models} />
</div>
)
}
}
import { resource, resourceProps } from 'redux-rails-resource'
@resource('user')
class UserProfile extends Component {
static propTypes = {
user: resourceProps.member
}
handleChangeName = (name) => {
const { id } = this.comments.attributes
// PUT request to /comments/:id
// Second argument will be body of post request
this.props.comments.update(id, { name })
}
render() {
const { name, company } = this.props.comments.attributes
return (
<div>
<NameField value={name} onSave={this.handleChangeName} />
<CompanyDisplay company={company} />
</div>
)
}
}
import { resource, resourceProps } from 'redux-rails-resource'
@resource('posts', { autoload: true })
class PaginatedPosts extends Component {
static propTypes = {
posts: resourceProps.collection
}
handlePageChange = (page) => {
this.props.comments.updateFilters({ page })
}
handleFilterSelect = (filter, value) => {
this.props.comments.updateFilters({ [filter]: value })
}
render() {
return (
<div>
<PaginationControl onPageChange={this.handlePageChange}
<Filters onFilterSelect={this.handleFilterSelect}
<PostList posts={this.posts.models} />
</div>
)
}
}
The resource
hoc will pass down 5 functions as top level keys in the prop passed to the wrapped component: index
, update
, create
, destroy
, and updateFilters
.
index(queryParams: object)
update(id: number, queryParams: object)
create(objectAttributes: object)
destroy(id: number)
updateFilters(partialQueryParams: object)
updateFilter will merge the existing queryParams of the corresponding resource with
the partialQueryParams
argument.
FAQs
Convenient Higher Order Component for React elements utilizing the Redux-Rails middleware
The npm package redux-rails-resource receives a total of 929 weekly downloads. As such, redux-rails-resource popularity was classified as not popular.
We found that redux-rails-resource demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.